llama_index icon indicating copy to clipboard operation
llama_index copied to clipboard

Trying whisper with SimpleDirectoryReader

Open myrulezzz opened this issue 1 year ago • 2 comments

So i am recording an mp3 and trying to return result fro simpledirecoryreader and make it speech. I can see my request transcripted however i have a problem with the reponse. Here is my response code:

Check if the response is not empty

if response: # Extract the top-ranked document as the answer top_doc = response[0].text
# Print the answer print(top_doc) else: print("No matching documents found.")

Print the API response

print(response)

Generate audio from transcript

language = 'en' tts = gTTS(text=top_doc, lang=language)

Save audio to file

filename = "output.mp3" with open(filename, "wb") as f: tts.write_to_fp(f)

Play audio using default media player

playsound("output.mp3") I get this error: raceback (most recent call last): File "/Users/andreasstylianou/Desktop/openai/./whisperdirectory.py", line 75, in top_doc = response[0].text
TypeError: 'Response' object is not subscriptable Any idea how to fix the response format?

myrulezzz avatar Mar 20 '23 23:03 myrulezzz

Hey @myrulezzz , how do you get your response object? Maybe taking a look at https://gpt-index.readthedocs.io/en/latest/reference/response.html would help.

Depends on if you want the final textual response (generated by the LLM), or the source nodes, you would need to call different methods.

Disiok avatar Mar 21 '23 17:03 Disiok

thanks @Disiok realy helpful and working

myrulezzz avatar Mar 22 '23 20:03 myrulezzz

sweet! going to close for now

jerryjliu avatar Mar 31 '23 04:03 jerryjliu