Deepak Kumar Singh
Deepak Kumar Singh

Reputation: 31

python program to find out start & end time of every word in a audio file

import speech_recognition as sr

r = sr.Recognizer()
framerate = 100
with sr.AudioFile("transcript.wav") as source:

    audio = r.record(source)

    decoder = r.recognize_sphinx(audio, show_all=False)

    print ([(seg.word, seg.start_frame/framerate)for seg in 
decoder.seg()])

I got the following error :

File "C:/Users/KUMAR/Downloads/untitled2.py", line 11, in print ([(seg.word, seg.start_frame/framerate)for seg in decoder.seg()])

AttributeError: 'str' object has no attribute 'seg'

How to fix that?

Upvotes: 3

Views: 1068

Answers (1)

Deepstop
Deepstop

Reputation: 3807

First, thanks for pointing me to the speech_recognition library. I didn't know it existed and I may have a use for it.

I see you have show_all=False but the docs say that to get a Decoder object it needs to be True, so instead it is just returning the transcription as a string.

Here's the excerpt

Returns the most likely transcription if show_all is false (the default). Otherwise, returns the Sphinx pocketsphinx.pocketsphinx.Decoder object resulting from the recognition.

Upvotes: 3

Related Questions