【问题标题】:Speech recognition not working in ubuntu语音识别在 ubuntu 中不起作用
【发布时间】:2018-04-02 15:20:47
【问题描述】:

我正在开始一项需要将​​音频转换为文本的工作。我正在使用 python 的语音识别库。我在 github 上看到了一个关于如何使用它的教程。该程序无法通过麦克风识别我的声音。

我在 ubuntu 16.04 上使用 python 2.7。

代码:

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    r.adjust_for_ambient_noise(source)
    audio = r.listen(source)

# recognize speech using Sphinx
try:
    print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
    print("Sphinx could not understand audio")
except sr.RequestError as e:
    print("Sphinx error; {0}".format(e))

github code link

终端输出:

shivam@shivam-HP-Pavilion-15-Notebook-PC:~/Python/audio$ python temp.py
ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
Say something!

在“说点什么!”之后,它一直在闪烁,但无法识别我的声音。

【问题讨论】:

  • alsa 行表明它无法控制混音器等。也许你应该告诉你操作系统的版本、Python 的版本,以及你是在 ssh 会话中运行它,还是在本地计算机上的 X11 终端上运行它。
  • @AnttiHaapala ubuntu 16.04,python 2.7 和本地计算机上的终端。
  • 它确实对我有用,我说了些什么,几秒钟后它打印了输出。我相信您已将麦克风静音,而那些 ALSA 警告(我也收到了)意味着它试图更改音量但失败了;您应该检查 Ubuntu 声音设置和 alsamixer。
  • @AnttiHaapala 我已附上我的声音设置中的照片。
  • 这是输出,不是输入:P 检查输入选项卡。

标签: python speech-recognition speech-to-text


【解决方案1】:

我无法安装 PocketSphinx 模块,遇到问题。 但如果我将recognize_sphinx 切换为recognize_google,它对我有用。

这是您修改后的代码。

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    r.adjust_for_ambient_noise(source)
    audio = r.listen(source)

# recognize speech using Sphinx
try:
    #print("Sphinx thinks you said " + r.recognize_sphinx(audio))
    print("Sphinx thinks you said " + r.recognize_google(audio))
except sr.UnknownValueError:
    print("Sphinx could not understand audio")
except sr.RequestError as e:
    print("Sphinx error; {0}".format(e))

输出

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
Say something!
Sphinx thinks you said hello
>>> 

希望这是有用的。

【讨论】:

  • 现在,甚至“说点什么”都不会出现在屏幕上。我已经安装了 pulseaudio 和 jack2。
猜你喜欢
  • 1970-01-01
  • 2012-07-31
  • 1970-01-01
  • 1970-01-01
  • 2018-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多