2

我有一个小的 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()
4

0 回答 0