Membaca file audio dengan SpeechRecognition

Pemrosesan Bahasa Lisan dengan Python

Daniel Bourke

Machine Learning Engineer/YouTube Creator

Kelas AudioFile

import speech_recognition as sr

# Siapkan instance recognizer recognizer = sr.Recognizer()
# Baca file audio clean_support_call = sr.AudioFile("clean-support-call.wav")
# Periksa tipe clean_support_call type(clean_support_call)
<class 'speech_recognition.AudioFile'>
Pemrosesan Bahasa Lisan dengan Python

Dari AudioFile ke AudioData

recognizer.recognize_google(audio_data=clean_support_call)
AssertionError: ``audio_data`` must be audio data
# Konversi dari AudioFile ke AudioData
with clean_support_call as source:

# Rekam audio clean_support_call_audio = recognizer.record(source)
# Periksa tipenya type(clean_support_call_audio)
<class 'speech_recognition.AudioData'>
Pemrosesan Bahasa Lisan dengan Python

Transkripsi AudioData kita

# Transkripsi panggilan dukungan bersih
recognizer.recognize_google(audio_data=clean_support_call_audio)
hello I'd like to get some help setting up my account please
Pemrosesan Bahasa Lisan dengan Python

Duration dan offset

  • duration dan offset keduanya None secara default
# Biarkan duration dan offset default
with clean_support_call as source:
    clean_support_call_audio = recognizer.record(source,
                                                 duration=None,
                                                 offset=None)
# Ambil 2 detik pertama panggilan dukungan
with clean_support_call as source:
    clean_support_call_audio = recognizer.record(source,
                                                 duration=2.0)
hello I'd like to get
Pemrosesan Bahasa Lisan dengan Python

Ayo berlatih!

Pemrosesan Bahasa Lisan dengan Python

Preparing Video For Download...