2016-11-18 7 views
0
import os 
blah = 'Umm' 

print('blah') 
os.system('say blah') 
"""so I want to make these two things linked, 
so that whenever I print something, it says that something 
""" 

필자는 print()를 호출 할 때마다 필자가 인쇄 한 것을 말하도록이 두 가지를 연결하고 싶다.두 명령 어를 파이썬으로 어떻게 연결합니까?

용어의 오용을 허용 할 수 있습니다.

+0

에 오신 것을 환영합니다 귀하의 print을 모두 교체는 단순한 케이스가 필요합니다 [그래서]. 당신이 요구하는 것을 말하기는 어렵습니다. [mcve]를 제공 할 수 있습니까? – TemporalWolf

+1

글쎄, 명백한 접근 방식은 함수를 만드는 것입니다 ... –

+0

저는 기본적으로 코드를 매우 길게 작성했기 때문에 모든 인쇄물을 수동으로 변경하는 것보다 쉬운 방법을 원합니다. – Void

답변

0

당신은 다음, 함수에 포장을 찾고에 printSay

import os 

def printSay(word): 
    print(word) 
    os.system('say {word}'.format(word=word)) 

# Usage 
printSay("Hello") 
0

say을 하위 프로세스로 실행하고 데이터를 표준 입력에 쓸 수 있습니다. 나는 espeak와 함께 리눅스에서 이것을했지만, 나는 명령의 권리가 있다고 생각한다.

import subprocess 

say = subprocess.Popen(["say", "-f", "-"], stdin=subprocess.PIPE) 

def myprint(*args): 
    print(*args) 
    say.stdin.write((' '.join(args) + '\n').encode('utf-8')) 

myprint("hello there")