Getting started with speech recognition and python

丶灬走出姿态 提交于 2019-11-28 22:28:00

问题


I would like to know where one could get started with speech recognition. Not with a library or anything that is fairly "Black Box'ed" But instead, I want to know where I can Actually make a simple speech recognition script. I have done some searching and found, not much, but what I have seen is that there are dictionaries of 'sounds' or syllables that can be pieced together to form text. So basically my question is where can I get started with this?

Also, since this is a little optimistic, I would also be fine with a library (for now) to use in my program. I saw that some speech to text libraries and APIs spit out only one results. This is ok, but it would be unrealiable. My current program already checks the grammar and everything of any text entered, so that way if I were to have say, the top ten results from the speech to text software, than It could check each and rule out any that don't make sense.


回答1:


UPDATE: this is not working anymore

because google closed its platform

--

you can use https://pypi.python.org/pypi/pygsr

$> pip install pygsr

example usage:

from pygsr import Pygsr
speech = Pygsr()
# duration in seconds
speech.record(3)
# select the language
phrase, complete_response = speech.speech_to_text('en_US')

print phrase



回答2:


If you really want to understand speech recognition from the ground up, look for a good signal processing package for python and then read up on speech recognition independently of the software.

But speech recognition is an extremely complex problem (basically because sounds interact in all sorts of ways when we talk). Even if you start with the best speech recognition library you can get your hands on, you'll by no means find yourself with nothing more to do.




回答3:


For those who want to get deeper into the subject of speech recognition in Python, here are some links:

  • http://www.slideshare.net/mchua/sigproc-selfstudy-17323823 - signal processing in Python, including Audio signal as the most interesting to play with.



回答4:


Pocketsphinx is also a good alternative. There are Python bindings provided through SWIG that make it easy to integrate in a script.

For example:

from os import environ, path
from itertools import izip

from pocketsphinx import *
from sphinxbase import *

MODELDIR = "../../../model"
DATADIR = "../../../test/data"

# Create a decoder with certain model
config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, 'hmm/en_US/hub4wsj_sc_8k'))
config.set_string('-lm', path.join(MODELDIR, 'lm/en_US/hub4.5000.DMP'))
config.set_string('-dict', path.join(MODELDIR, 'lm/en_US/hub4.5000.dic'))
decoder = Decoder(config)

# Decode static file.
decoder.decode_raw(open(path.join(DATADIR, 'goforward.raw'), 'rb'))

# Retrieve hypothesis.
hypothesis = decoder.hyp()
print 'Best hypothesis: ', hypothesis.best_score, hypothesis.hypstr

print 'Best hypothesis segments: ', [seg.word for seg in decoder.seg()]

# Access N best decodings.
print 'Best 10 hypothesis: '
for best, i in izip(decoder.nbest(), range(10)):
    print best.hyp().best_score, best.hyp().hypstr

# Decode streaming data.
decoder = Decoder(config)
decoder.start_utt('goforward')
stream = open(path.join(DATADIR, 'goforward.raw'), 'rb')
while True:
    buf = stream.read(1024)
    if buf:
        decoder.process_raw(buf, False, False)
    else:
        break
decoder.end_utt()
print 'Stream decoding result:', decoder.hyp().hypstr



回答5:


I know the Question is old but just for people in future:

I use the speech_recognition-Module and I love it. The only thing is, it requires Internet because it uses the Google to recognize the Speech. But that shouldn't be a problem in most cases. The recognition works almost perfectly.

EDIT:

The speech_recognition package can use more than just google to translate, including CMUsphinx (which allows offline recognition), among others. The only difference is a subtle change in the recognize command:

https://pypi.python.org/pypi/SpeechRecognition/

Here is a small code-example:

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone() as source:                # use the default microphone as the audio source
    audio = r.listen(source)                   # listen for the first phrase and extract it into audio data

try:
    print("You said " + r.recognize_google(audio))    # recognize speech using Google Speech Recognition - ONLINE
    print("You said " + r.recognize_sphinx(audio))    # recognize speech using CMUsphinx Speech Recognition - OFFLINE
except LookupError:                            # speech is unintelligible
    print("Could not understand audio")

There is just one thing what doesn't work well for me: Listening in an infinity loop. After some Minutes it hangs up. (It's not crashing, it's just not responding.)

EDIT: If you want to use Microphone without the infinity loop you should specify recording length. Example code:

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone() as source:
    print("Speak:")
    audio = r.listen(source, None, "time_to_record")  # recording



回答6:


Dragonfly provides a clean framework for speech recognition on Windows. Check their Documentation for example usage. Since you aren't looking for the big scale of features Dragonfly provides you might want to take a look at the no longer maintained PySpeech library.

Their source code looks easy to understand and maybe that's what you want to look at first



来源:https://stackoverflow.com/questions/12239080/getting-started-with-speech-recognition-and-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!