Prathamesh1420 commited on
Commit
7925d15
1 Parent(s): df287c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -71,6 +71,8 @@ def text_to_speech(text, tts_api_key):
71
  return f"Error in TTS conversion: {str(e)}"
72
 
73
  # Process audio function to handle transcription, response generation, and TTS
 
 
74
  def process_audio(audio, groq_api_key, tts_api_key):
75
  if not groq_api_key:
76
  return "Please enter your Groq API key.", "API key is required.", None
@@ -81,7 +83,16 @@ def process_audio(audio, groq_api_key, tts_api_key):
81
  # Convert the AI response to speech using VoiceRSS
82
  audio_response = text_to_speech(response, tts_api_key)
83
 
84
- return transcription, response, audio_response
 
 
 
 
 
 
 
 
 
85
 
86
  # Gradio interface with TTS
87
  with gr.Blocks(theme=gr.themes.Default()) as demo:
 
71
  return f"Error in TTS conversion: {str(e)}"
72
 
73
  # Process audio function to handle transcription, response generation, and TTS
74
+ import tempfile
75
+
76
  def process_audio(audio, groq_api_key, tts_api_key):
77
  if not groq_api_key:
78
  return "Please enter your Groq API key.", "API key is required.", None
 
83
  # Convert the AI response to speech using VoiceRSS
84
  audio_response = text_to_speech(response, tts_api_key)
85
 
86
+ if isinstance(audio_response, bytes): # Check if we received valid audio bytes
87
+ # Save audio response to a temporary file
88
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
89
+ tmp_file.write(audio_response)
90
+ tmp_filepath = tmp_file.name # Get the file path
91
+
92
+ return transcription, response, tmp_filepath # Return the file path for Gradio audio output
93
+ else:
94
+ return transcription, response, None # If there's an error with TTS, return None for audio output
95
+
96
 
97
  # Gradio interface with TTS
98
  with gr.Blocks(theme=gr.themes.Default()) as demo: