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で学ぶ音声言語処理

Your turn!

Pythonで学ぶ音声言語処理

Preparing Video For Download...