SpeechRecognition Python 库

Python 语音语言处理

Daniel Bourke

Machine Learning Engineer/YouTube Creator

为何选择 SpeechRecognition 库?

一些现有的 Python 库

  • CMU Sphinx
  • Kaldi
  • SpeechRecognition
  • Facebook 的 Wav2letter++
Python 语音语言处理

开始使用 SpeechRecognition

从 PyPi 安装:

$ pip install SpeechRecognition
  • 兼容 Python 2 和 3
  • 本课使用 Python 3
Python 语音语言处理

使用 Recognizer 类

# 导入 SpeechRecognition 库
import speech_recognition as sr

# 创建 Recognizer 实例 recognizer = sr.Recognizer()
# 设置能量阈值 recognizer.energy_threshold = 300
Python 语音语言处理

用 Recognizer 识别语音

  • Recognizer 类内置与语音 API 交互的函数
    • recognize_bing()
    • recognize_google()
    • recognize_google_cloud()
    • recognize_wit()

输入:audio_file

输出:audio_file 的转写文本

Python 语音语言处理

SpeechRecognition 示例

  • 重点:recognize_google()

  • 用 SpeechRecognition 从音频文件识别语音:

# 导入 SpeechRecognition 库
import speech_recognition as sr

# 实例化 Recognizer 类 recognizer = sr.Recognizer()
# 使用 Google Web API 转写语音 recognizer.recognize_google(audio_data=audio_file language="en-US")
在 DataCamp 学习语音识别太棒了!
Python 语音语言处理

轮到你了!

Python 语音语言处理

Preparing Video For Download...