K
K
Keste ...2018-10-19 18:03:45
Python
Keste ..., 2018-10-19 18:03:45

Python 3 how not to output operations with os, sys, subprocess modules to the console?

One of the code examples that I'm running but don't want to output anything to the terminal:

def j_say(phrase):
    os.system('curl "https://tts.voicetech.yandex.net/generate?format=wav&lang=ru-RU&speaker=zahar&emotion=good&key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -G --data-urlencode "text=' + phrase + '" > j_speech.wav')
    os.system('aplay j_speech.wav')

And it outputs this:
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  133k    0  133k    0     0   496k      0 --:--:-- --:--:-- --:--:--  496k
Воспроизведение WAVE 'j_speech.wav' : Signed 16 bit Little Endian, Частота 48000 Гц, Моно

Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
chupasaurus, 2018-10-19
@chupasaurus

os, sys, subprocess

Mixed into a bunch of horses and people. The output of commands run through subprocessis controlled via the stderr/stdout options of the Popen class constructor, just by default the output will be merged with the main program.
Learn to read documentation.

V
Vladimir, 2018-10-19
@RamzanKadyrovPWNZ

Try this.
Drink for yourself, read about subprocess. There the dock is understandable.

import os,sys,subprocess


def j_say(phrase):
  
    arg = subprocess.Popen(['curl','--basic','pornhub.com'],stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
    return arg.stdout.read().decode("cp866")


print(j_say(('abr')))

Remove print() and the output to the terminal will disappear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question