我有一个小型Python脚本,用于设置PulseAudio,以便Festival语音合成程序可以将合成语音传输到Skype调用中。这是为了让无法说话的人能够在常规的Skype小组会议上发表意见。
它可以工作,但让设置工作涉及到与PulseAudio音量控制GUI的很多交互。如何通过终端中的脚本设置PulseAudio流?
小脚本如下:
import os
import subprocess
import signal
def main():
raw_input(
"\nReady to load a dummy sound card driver...\n" +\
"Press Enter to continue."
)
os.system("sudo modprobe snd-dummy")
raw_input(
"\nReady to set Festival running...\n" +\
"Press Enter to continue."
)
process_Festival = subprocess.Popen(
["festival", "--tts", "/var/log/dmesg"],
preexec_fn = os.setsid
)
raw_input(
"\nReady to open PulseAudio Volume Control...\n" +\
"Press Enter to continue.")
os.system("pavucontrol &")
raw_input(
"\nIn PulseAudio Volume Control, select the tab \"Playback\".\n" +\
"Identify Festival in operaton.\n" +\
"Change the output sink of Festival to \"Dummy Analog Stereo\".\n" +\
"Press Enter to continue."
)
raw_input(
"\nReady to stop Festival running...\n" +\
"Press Enter to continue."
)
os.killpg(os.getpgid(process_Festival.pid), 9)
raw_input(
"\nIn PulseAudio Volume Control, select the tab \"Recording\".\n" +\
"Start a Skype call to \"Skype Test Call\".\n" +\
"In PulseAudio Volume Control, identify Skype in operation.\n" +\
"Change the input source of Skype to \"Monitor of Dummy Analog " +\
"Stereo\"\n" +\
"End the Skype call.\n" +\
"Press Enter to continue."
)
raw_input(
"\nReady for text entry speech synthesis broadcast to Skype...\n" +\
"Press Enter to continue (and then make the Skype call when ready).\n"
)
while True:
text = raw_input("> ")
os.system("echo \"{text}\" | festival --tts".format(text = text))
if __name__ == "__main__":
main()