uasername commited on
Commit
6add177
·
verified ·
1 Parent(s): 110ac6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -56,7 +56,7 @@ def lookup_definition(query: str) -> AgentText:
56
 
57
 
58
 
59
- AUDIO_OUTPUT_PATH = "/tmp/response.mp3"
60
 
61
 
62
  @tool
@@ -68,10 +68,26 @@ def text_to_speech(text: str) -> AgentAudio:
68
  Returns:
69
  AgentAudio: An AgentAudio instance containing the file path to the generated audio.
70
  """
 
 
 
 
 
71
  tts = gTTS(text=text, lang='en')
72
  tts.save(AUDIO_OUTPUT_PATH)
73
- return AgentAudio(AUDIO_OUTPUT_PATH)
74
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
 
77
  # # Define the audio output path
 
56
 
57
 
58
 
59
+
60
 
61
 
62
  @tool
 
68
  Returns:
69
  AgentAudio: An AgentAudio instance containing the file path to the generated audio.
70
  """
71
+ from gtts import gTTS
72
+ import os
73
+
74
+ AUDIO_OUTPUT_PATH = "/tmp/response.mp3"
75
+
76
  tts = gTTS(text=text, lang='en')
77
  tts.save(AUDIO_OUTPUT_PATH)
 
78
 
79
+ # Read the MP3 bytes directly
80
+ with open(AUDIO_OUTPUT_PATH, "rb") as f:
81
+ audio_bytes = f.read()
82
+
83
+ #return AgentAudio(AUDIO_OUTPUT_PATH)
84
+
85
+ # Read the MP3 bytes directly
86
+ with open(AUDIO_OUTPUT_PATH, "rb") as f:
87
+ audio_bytes = f.read()
88
+
89
+ # Return AgentAudio, but store the raw bytes
90
+ return AgentAudio(audio_bytes) # Not a path anymore
91
 
92
 
93
  # # Define the audio output path