在实现键盘控制程序开始之后,实现自动录音生成pcm格式function。
要考虑的问题:实时录音,录音结束的条件(阈值)。主要工具: speech_recognition包,代码简单、效果好。
主要参考: github
https://github.com/Uberi/speech_recognition
博客:
Python3从零开始搭建一个语音对话机器人
https://blog.csdn.net/NIeson2012/article/details/96476878
speech_recognition
https://pypi.org/project/SpeechRecognition/
pip install SpeechRecognition (时间比较久)崩溃
pip3 install -i https://pypi.doubanio.com/simple/ SpeechRecognition
只安装SpeechRecognition是不够的,现在运行会报错,提示找不到PyAudio
Requirements
To
use all of the functionality of the library, you should have:
· Python 2.6, 2.7, or 3.3+ (required)
· PyAudio 0.2.11+ (required only if you need to use microphone input, Microphone)
尝试python -m pip install pyaudio 不行
尝试pip3 install -i https://pypi.doubanio.com/simple/ pyaudio 不行
https://blog.csdn.net/Sau_Hit/article/details/85938063
https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
不知道哪个设备,先打印出设备信息
import speech_recognition as sr
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
with sr.Microphone(sample_rate = rate, device_index = 1 ) as source:
找到之后加上
recognizer_instance.energy_threshold
recognizer_instance.pause_threshold
参考
https://pypi.org/project/SpeechRecognition/1.2.1/
https://pypi.org/project/SpeechRecognition/
https://github.com/Uberi/speech_recognition/blob/c89856088ad81d81d38be314e3db50905481c5fe/speech_recognition/init.py
The recognizer
hangs on recognizer_instance.listen;
specifically, when it’s calling Microphone.MicrophoneStream.read.
This
usually happens when you’re using a Raspberry Pi board,
This causes the default microphone used by PyAudio to simply block when we try to read
it. need a USB sound card (or USB microphone). Once you do this, change all
instances of Microphone() to Microphone(device_index
= MICROPHONE_INDEX), where MICROPHONE_INDEX is the hardware-specific index of the microphone.