Thư viện Python SpeechRecognition

Xử lý Ngôn ngữ Nói bằng Python

Daniel Bourke

Machine Learning Engineer/YouTube Creator

Vì sao dùng thư viện SpeechRecognition?

Một số thư viện Python hiện có

  • CMU Sphinx
  • Kaldi
  • SpeechRecognition
  • Wav2letter++ của Facebook
Xử lý Ngôn ngữ Nói bằng Python

Bắt đầu với SpeechRecognition

Cài từ PyPi:

$ pip install SpeechRecognition
  • Tương thích Python 2 và 3
  • Khóa học dùng Python 3
Xử lý Ngôn ngữ Nói bằng Python

Sử dụng lớp Recognizer

# Import thư viện SpeechRecognition
import speech_recognition as sr

# Tạo một đối tượng Recognizer recognizer = sr.Recognizer()
# Đặt ngưỡng năng lượng recognizer.energy_threshold = 300
Xử lý Ngôn ngữ Nói bằng Python

Dùng Recognizer để nhận dạng giọng nói

  • Lớp Recognizer có sẵn hàm tương tác với các API nhận dạng giọng nói
    • recognize_bing()
    • recognize_google()
    • recognize_google_cloud()
    • recognize_wit()

Đầu vào: audio_file

Đầu ra: văn bản nhận dạng từ audio_file

Xử lý Ngôn ngữ Nói bằng Python

Ví dụ về SpeechRecognition

  • Tập trung vào recognize_google()

  • Nhận dạng từ tệp âm thanh với SpeechRecognition:

# Import thư viện SpeechRecognition
import speech_recognition as sr

# Khởi tạo lớp Recognizer recognizer = sr.Recognizer()
# Phiên âm bằng Google Web API recognizer.recognize_google(audio_data=audio_file language="en-US")
Học nhận dạng giọng nói trên DataCamp thật tuyệt!
Xử lý Ngôn ngữ Nói bằng Python

Đến lượt bạn!

Xử lý Ngôn ngữ Nói bằng Python

Preparing Video For Download...