Odczytywanie plików audio za pomocą SpeechRecognition

Przetwarzanie mowy w Pythonie

Daniel Bourke

Machine Learning Engineer/YouTube Creator

Klasa AudioFile

import speech_recognition as sr

# Setup recognizer instance recognizer = sr.Recognizer()
# Read in audio file clean_support_call = sr.AudioFile("clean-support-call.wav")
# Check type of clean_support_call type(clean_support_call)
<class 'speech_recognition.AudioFile'>
Przetwarzanie mowy w Pythonie

Z AudioFile do AudioData

recognizer.recognize_google(audio_data=clean_support_call)
AssertionError: ``audio_data`` must be audio data
# Convert from AudioFile to AudioData
with clean_support_call as source:

# Record the audio clean_support_call_audio = recognizer.record(source)
# Check the type type(clean_support_call_audio)
<class 'speech_recognition.AudioData'>
Przetwarzanie mowy w Pythonie

Transkrypcja danych AudioData

# Transcribe clean support call
recognizer.recognize_google(audio_data=clean_support_call_audio)
hello I'd like to get some help setting up my account please
Przetwarzanie mowy w Pythonie

Parametry duration i offset

  • duration i offset domyślnie mają wartość None
# Leave duration and offset as default
with clean_support_call as source:
    clean_support_call_audio = recognizer.record(source,
                                                 duration=None,
                                                 offset=None)
# Get first 2-seconds of clean support call
with clean_support_call as source:
    clean_support_call_audio = recognizer.record(source,
                                                 duration=2.0)
hello I'd like to get
Przetwarzanie mowy w Pythonie

Czas na ćwiczenia!

Przetwarzanie mowy w Pythonie

Preparing Video For Download...