我正在尝试将 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