Python 同时进行文字转语音和语音识别
Python text-to-speech and speech-recognition at the same time
我正在尝试创建一个自言自语的 python 脚本。 (例如:https://vimeo.com/172440766)
已经可以实现文字转语音和语音识别了,但是还没有找到同时实现的方法
有没有办法并行执行这两项任务?
感谢任何建议。
如果您需要同时完成某些事情,请查看线程库:https://docs.python.org/3/library/threading.html
一个想法是在主控制流之外为您的语音识别创建一个线程,因为我想这将在大多数时间处于活动状态。首先你可以这样做:
import threading
class SpeechRecognition(threading.Thread):
def __init__(self, parent=None):
super().__init__()
self.parent = parent
def run(self):
(your speech recognition function/code here)
并开始语音识别:
process = SpeechRecognition()
process.start()
我正在尝试创建一个自言自语的 python 脚本。 (例如:https://vimeo.com/172440766) 已经可以实现文字转语音和语音识别了,但是还没有找到同时实现的方法
有没有办法并行执行这两项任务? 感谢任何建议。
如果您需要同时完成某些事情,请查看线程库:https://docs.python.org/3/library/threading.html
一个想法是在主控制流之外为您的语音识别创建一个线程,因为我想这将在大多数时间处于活动状态。首先你可以这样做:
import threading
class SpeechRecognition(threading.Thread):
def __init__(self, parent=None):
super().__init__()
self.parent = parent
def run(self):
(your speech recognition function/code here)
并开始语音识别:
process = SpeechRecognition()
process.start()