简体   繁体   English

语音识别在ubuntu中不起作用

[英]Speech recognition not working in ubuntu

I am starting a work which needs to convert audio into text. 我正在开始一项需要将​​音频转换为文本的作品。 I am using the speechrecognition library of python. 我正在使用python的speechrecognition库。 I saw a tutorial on github on how to use it. 我在github上看到了如何使用它的教程。 The program is not bale to recognise my voice through microphone. 该程序并不能通过麦克风识别我的声音。

I am using python 2.7 on ubuntu 16.04. 我在ubuntu 16.04上使用python 2.7。

Code: 码:

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 github代码链接

Output on terminal: 终端输出:

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!

After, "Say something!", it keeps on blinking but my voice is not recognised. 之后,“说点什么!”,它继续闪烁,但我的声音无法识别。

麦克风设置

I couldn't get PocketSphinx module installed , running into issues. 我无法安装PocketSphinx模块, PocketSphinx问题。 But if I switch recognize_sphinx with recognize_google , its working for me. 但是,如果我切换recognize_sphinxrecognize_google ,它为我工作。

Here is your modified code. 这是您修改过的代码。

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))

Output 产量

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
>>> 

Hope this is useful. 希望这很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM