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 クラスを使う

# Import the SpeechRecognition library
import speech_recognition as sr

# Create an instance of Recognizer recognizer = sr.Recognizer()
# Set the energy threshold 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 で音声ファイルから音声を認識します:

# Import SpeechRecognition library
import speech_recognition as sr

# Instantiate Recognizer class recognizer = sr.Recognizer()
# Transcribe speech using Google web API recognizer.recognize_google(audio_data=audio_file, language="en-US")
Learning speech recognition on DataCamp is awesome!
Pythonで学ぶ音声言語処理

挑戦してみましょう!

Pythonで学ぶ音声言語処理

Preparing Video For Download...