llama_index
llama_index copied to clipboard
Trying whisper with SimpleDirectoryReader
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
TypeError: 'Response' object is not subscriptable
Any idea how to fix the response format?
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.
thanks @Disiok realy helpful and working
sweet! going to close for now