【问题标题】:How to run Espeak and Pocketsphinx simultaneously?如何同时运行 Espeak 和 Pocketsphinx?
【发布时间】:2019-09-03 17:31:06
【问题描述】:

我正在尝试将 Pocketsphinx 与 Espeak 一起运行,这样当一个单词被识别时,它会以文本到语音的形式回复。

我已经让这两个草图都工作了,但是一旦 Pocketsphinx 运行,Espeak 就会停止工作。没有错误,只是没有声音。

所以不知道出了什么问题?我需要在单独的线程中运行它们还是一个阻塞另一个?

from pocketsphinx import LiveSpeech
from subprocess import call
import pyttsx3
import os

def speak(txt):
    print("speaking: "+txt)
    call(["sudo", "espeak", txt])

def init_speech():
    return LiveSpeech(
        audio_device = None,
        sampling_rate=16000,
        lm=False,
        kws=keyword_dir)

speak('hello world one') # this works

root_dir = os.path.dirname(os.path.abspath(__file__))
keyword_dir = os.path.join(root_dir, 'data/keyphrase.list')

speech = init_speech()

speak('hello world two') # and now it does not work

while True:
    for phrase in speech:
        topWord = phrase.segments()[0]
        print(topWord) #this works
        speak(topWord) # this is the goal

【问题讨论】:

    标签: python pocketsphinx espeak


    【解决方案1】:

    我找到了解决问题的方法。 Espeak 没有使用正确的声卡,因为 pocketsphinx 安装了 pulseaudio。要指定 Espeak 将音频发送到何处以使用标志 stdout:

    --标准输出 | aplay -D "sysdefault:CARD=seeed2micvoicec"

    使用命令 aplay -L 查找您的卡的名称

    from pocketsphinx import LiveSpeech
    import os
    
    def speak(txt):
        os.system('espeak "'+txt+'" --stdout | aplay -D "sysdefault:CARD=seeed2micvoicec"')
        print("TtS: " + txt)
    
    def init_speech():
        return LiveSpeech(
            audio_device = None,
            sampling_rate=16000,
            lm=False,
            kws=keyword_dir)
    
    speak('hello world one') # this works
    
    root_dir = os.path.dirname(os.path.abspath(__file__))
    keyword_dir = os.path.join(root_dir, 'keyphrase.list')
    
    speech = init_speech()
    print("running")
    speak('hello world two') # and now it does not work
    
    while True:
        for phrase in speech:
            topWord = phrase.segments()[0]
            print(phrase) #this works
            speak(topWord) # this is the goal
    

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 1970-01-01
      • 2020-07-20
      • 2019-11-25
      • 1970-01-01
      • 2011-07-23
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多