Recording the audio we need
Sometimes you may not want the entire audio file you're working with. The duration and offset parameters of the record() method can help with this.
After exploring your dataset, you find there's one file, imported as nothing_at_end which has 30-seconds of silence at the end and a support call file, imported as out_of_warranty has 3-seconds of static at the front.
Setting duration and offset means the record() method will record up to duration audio starting at offset. They're both measured in seconds.
Bu egzersiz
Spoken Language Processing in Python
kursunun bir parçasıdırUygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Convert AudioFile to AudioData
with nothing_at_end as source:
nothing_at_end_audio = recognizer.record(source,
duration=____,
offset=None)
# Transcribe AudioData to text
text = recognizer.recognize_google(nothing_at_end_audio,
language="en-US")
print(text)