我想知道哪里可以开始使用语音识别。不是图书馆或任何相当“黑盒子”的东西“而是,我想知道我在哪里可以实际制作一个简单的语音识别脚本。我做了一些搜索并发现,并不多,但我所看到的是有“声音”或音节的词典可以拼凑在一起形成文本。所以基本上我的问题是我可以从哪里开始这个?
另外,由于这有点乐观,我也可以在我的程序中使用库(现在)。我看到文本库和API的一些演讲只吐出一个结果。这没关系,但这是不可能的。我当前的程序已经检查语法和输入的任何文本的所有内容,所以如果我要说,从语音到文本软件的前十个结果,它可以检查每个并排除任何没有意义的文本
答案 0 :(得分:8)
如果您真的想从头开始理解语音识别,请为python寻找一个好的信号处理软件包,然后单独阅读该软件的语音识别 。
但是语音识别是一个非常复杂的问题(主要是因为当我们说话时,声音以各种方式相互作用)。即使你从最好的语音识别库开始,你也可以亲自动手,你决不会发现自己没有更多的事可做。
答案 1 :(得分:7)
因为谷歌关闭了她的平台
-
您可以使用https://pypi.python.org/pypi/pygsr
$> pip install pygsr
示例用法:
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 :(得分:6)
Pocketsphinx也是一个不错的选择。通过SWIG提供的Python绑定可以很容易地集成到脚本中。
例如:
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
答案 3 :(得分:6)
对于那些想要深入了解Python语音识别主题的人来说,这里有一些链接:
答案 4 :(得分:4)
Dragonfly为Windows上的语音识别提供了一个干净的框架。检查他们的Documentation示例用法。由于您没有寻找Dragonfly提供的大规模功能,因此您可能需要查看不再维护的PySpeech库。
他们的源代码看起来很容易理解,也许这就是你想要先看的内容
答案 5 :(得分:4)
我知道这个问题已经陈旧,但仅限于未来的人们:
我使用speech_recognition
- 模块,我喜欢它。 唯一的问题是,它需要互联网,因为它使用谷歌识别语音。但在大多数情况下,这不应该是一个问题。识别工作几乎完美。
修改强>
speech_recognition
软件包可以使用的不仅仅是谷歌翻译,包括CMUsphinx(允许离线识别)等。唯一的区别是识别命令的微妙变化:
https://pypi.python.org/pypi/SpeechRecognition/
这是一个小代码示例:
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")
只有一件事对我不起作用:在无限循环中聆听。几分钟后,它就会挂断。 (它没有崩溃,它只是没有响应。)
编辑: 如果要在没有无限循环的情况下使用麦克风,则应指定录制长度。 示例代码:
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 :(得分:0)
这可能是最重要的要学习的东西:基本概念 信号处理,特别是数字信号处理(DSP)。 对抽象概念的一点了解将为您做准备 scipy.signal中令人困惑的工具聚宝盆。
首先是模数转换(ADC)。这真的在领域 如今是录音过程的一部分, 即使您所做的只是将麦克风连接到计算机上。
如果您从模拟录音开始,这可能是一个问题 将旧的录音带或黑胶唱片打成数字形式, 或从旧的录像带中提取音频。最容易玩的 将其输入计算机的音频输入插孔并使用内置的 捕获原始线性脉冲编码调制的硬件和软件 (LPCM)数字信号到文件。您提到的Audacity是一个 很棒的工具,还有更多。
傅立叶变换是您的朋友。用数据科学的术语是 非常适合特征提取和特征空间尺寸缩减, 特别是如果您正在寻找能够改变声音变化的功能 在整个样本过程中。这里没有空间可以解释,但是 时域中的原始数据对于机器学习而言要困难得多 算法要比频域中的原始数据处理。
特别是,您将使用快速傅立叶变换(FFT), 离散傅里叶变换(DFT)的一种非常有效的形式。如今 FFT通常在DSP硬件中完成。
答案 7 :(得分:0)
import speech_recognition as SRG
import time
store = SRG.Recognizer()
with SRG.Microphone() as s:
print("Speak...")
audio_input = store.record(s, duration=7)
print("Recording time:",time.strftime("%I:%M:%S"))
try:
text_output = store.recognize_google(audio_input)
print("Text converted from audio:\n")
print(text_output)
print("Finished!!")
print("Execution time:",time.strftime("%I:%M:%S"))
except:
print("Couldn't process the audio input.")
这应该有效。您会将来自默认麦克风的音频输入保存为 text_output 变量中的文本形式。 您可以查看此链接了解更多信息:https://www.journaldev.com/37873/python-speech-to-text-speechrecognition
我们基本上做的是首先从麦克风录制音频,然后我们使用该音频作为语音识别器的输入。
唯一的问题是您需要有效的互联网连接以及这两个必需的 Python 库 speech_recognition
和 pyaudio
。