使用 SpeechRecognition 库
为了避免每次都输入 speech_recognition,我们将其按 sr 导入。
我们还将创建一个 Recognizer 类的实例,供后续使用。
energy_threshold 是介于 0 到 4000 之间的数值,用于控制 Recognizer 类应当在音频文件中监听到何种能量水平。
当识别器类监听音频时,energy_threshold 会动态调整。
本练习是课程的一部分
Python 语音语言处理
练习说明
- 将
speech_recognition库按sr导入。 - 创建一个
Recognizer类的实例,并保存为recognizer。 - 将
recognizer.energy_threshold设为 300。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Importing the speech_recognition library
import ____ as ____
# Create an instance of the Recognizer class
____ = sr.____()
# Set the energy threshold
recognizer.____ = ____