【问题标题】:Creating an array of words from a stream of audio from speech-recognition从语音识别的音频流中创建单词数组
【发布时间】:2018-03-19 08:44:26
【问题描述】:

所以我目前正在使用 python 库“SpeechRecognition”,以便从我的麦克风接收到的音频的暂停之间获取短语。

但是,我需要的是能够在我不断说话的同时将每个单词打印出来。但我不知道该怎么做。

我最终会分析一组单词以寻找关键短语。我的计划是使用多线程来定期分析代码。

这是我当前的代码

import string
import threading
import speech_recognition as sr

from threading import Thread

# obtain audio
def voiceRecognition():
    while True:
        audioText = ''
        r = sr.Recognizer()
        with sr.Microphone() as source:
            audio = r.listen(source)
            try:
                audioText = r.recognize_google(audio)
                print(audioText)
            except sr.UnknownValueError:
                pass


if __name__ == '__main__':
    Thread(target = voiceRecognition).start()

【问题讨论】:

标签: python speech-recognition pyaudio


【解决方案1】:

将我的工作与您的工作进行比较,我会将 try 块放在 with sr.Microphone()... 块之外/与with sr.Microphone()... 块相同的级别,如下所示

    with sr.Microphone() as source:
        audio = r.listen(source)
   try:
        audioText = r.recognize_google(audio)
        print(audioText)

另外,可能超出了问题的范围,但我使用了 TextBlob (https://pypi.python.org/pypi/textblob) 包,它使用 NLTK 平台 (http://www.nltk.org/) 。您可能会对解析结果感兴趣。

【讨论】:

  • 哇,这是很久以前的事了,我完全忘记了这一点。这个 nltk 的东西看起来很酷,我得去看看。但是我找到了答案,完全忘记了回答。
【解决方案2】:

我使用了多线程并将每个线程可以录制的音频量限制为 5 秒,以便 Google 可以处理翻译的长度。当一个线程完成监听后,它会允许一个新线程进入,然后它会进行翻译,等等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多