Pijush2023 commited on
Commit
680dd01
·
verified ·
1 Parent(s): 193ef9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -92,18 +92,26 @@ def generate_audio_elevenlabs(text):
92
  "use_speaker_boost": False
93
  }
94
  }
95
- response = requests.post(tts_url, headers=headers, json=data, stream=True)
96
- if response.ok:
97
- with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
98
- for chunk in response.iter_content(chunk_size=1024):
99
- if chunk:
100
- f.write(chunk)
101
- audio_path = f.name
102
- return audio_path # Return audio path for automatic playback
103
- else:
104
- logging.error(f"Error generating audio: {response.text}")
 
 
 
 
 
 
 
105
  return None
106
 
 
107
  # Define the ASR model with Whisper
108
  model_id = 'openai/whisper-large-v3'
109
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
 
92
  "use_speaker_boost": False
93
  }
94
  }
95
+
96
+ try:
97
+ response = requests.post(tts_url, headers=headers, json=data, stream=True)
98
+ if response.ok:
99
+ # Create a proper temporary file for saving the audio response
100
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
101
+ for chunk in response.iter_content(chunk_size=1024):
102
+ if chunk:
103
+ f.write(chunk)
104
+ audio_path = f.name # Get the path of the saved audio file
105
+ logging.debug(f"Audio saved to {audio_path}")
106
+ return audio_path # Ensure the path is to a valid audio file
107
+ else:
108
+ logging.error(f"Error generating audio: {response.text}")
109
+ return None
110
+ except Exception as e:
111
+ logging.error(f"Exception in generating audio: {str(e)}")
112
  return None
113
 
114
+
115
  # Define the ASR model with Whisper
116
  model_id = 'openai/whisper-large-v3'
117
  device = "cuda:0" if torch.cuda.is_available() else "cpu"