失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python音频提取pcm_python 实现录音pcm格式功能

python音频提取pcm_python 实现录音pcm格式功能

时间:2021-09-30 08:13:28

相关推荐

python音频提取pcm_python 实现录音pcm格式功能

一、目的

在实现键盘控制程序开始之后,实现自动录音生成pcm格式function。

要考虑的问题:实时录音,录音结束的条件(阈值)。主要工具: speech_recognition包,代码简单、效果好。

二、电脑录音 (包括使用树莓派时的问题)

主要参考: github

/Uberi/speech_recognition

博客:

Python3从零开始搭建一个语音对话机器人

/NIeson/article/details/96476878

三、code

speech_recognition

/project/SpeechRecognition/

第一步、安装SpeechRecognition

pip install SpeechRecognition (时间比较久)崩溃

pip3 install -i /simple/ SpeechRecognition

只安装SpeechRecognition是不够的,现在运行会报错,提示找不到PyAudio

第二步、安装 pip install 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 /simple/ pyaudio 不行

解决: whl文件在python\Scripts下安装

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

找到之后加上

第一次不能识别speech,可能原因recognizer_instance.energy_threshold设置太高,尝试调小或者提前recognizer_instance.adjust_for_ambient_noise动态调整。

recognizer_instance.energy_threshold

recognizer_instance.pause_threshold

参考

/project/SpeechRecognition/1.2.1/

/project/SpeechRecognition/

/Uberi/speech_recognition/blob/c89856088ad81d81d38be314e3db50905481c5fe/speech_recognition/init.py

使用树莓派 Raspberry Pi board,

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.

如果觉得《python音频提取pcm_python 实现录音pcm格式功能》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。