Gregniuki commited on
Commit
fe50d5a
·
1 Parent(s): 99dc084

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -142,13 +142,27 @@ async def main(
142
  # noise_scale_w = noise_scale_w_slider.value
143
  auto_play = play
144
  audio = inferencing(model, config, 0, text_input, speed_slider, noise_scale_slider, noise_scale_w_slider, auto_play)
145
- temp_audio_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
146
- audio.export(temp_audio_file.name, format="mp3")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  # Rename the temporary audio file based on the text input
149
- global renamed_audio_file
150
- renamed_audio_file = os.path.join(tempfile.gettempdir(), f"{text_input}.mp3")
151
- os.rename(temp_audio_file.name, renamed_audio_file)
152
  if config["num_speakers"] > 1:
153
  speaker_selection.options = config["speaker_id_map"].values()
154
  speaker_selection.layout.visibility = 'visible'
@@ -209,7 +223,7 @@ async def main(
209
 
210
 
211
  # Save the audio as a temporary WAV file
212
- return templates.TemplateResponse("interface.html", {"request": request, "audio_file": temp_audio_file, "data": data})
213
 
214
 
215
  # return {"message": f"Text to synthesize: {text_input}, Speed: {speed_slider}, Play: {play}"}
 
142
  # noise_scale_w = noise_scale_w_slider.value
143
  auto_play = play
144
  audio = inferencing(model, config, 0, text_input, speed_slider, noise_scale_slider, noise_scale_w_slider, auto_play)
145
+ temp_dir = tempfile.mkdtemp()
146
+ play)
147
+
148
+ # Create a temporary directory to store the audio files
149
+ temp_dir = tempfile.mkdtemp()
150
+
151
+ # Export the audio to an MP3 file in the temporary directory
152
+ temp_audio_file = os.path.join(temp_dir, "generated_audio.mp3")
153
+ audio.export(temp_audio_file, format="mp3")
154
+
155
+ # Rename the audio file based on the text input
156
+ renamed_audio_file = os.path.join(temp_dir, f"{text_input}.mp3")
157
+ os.rename(temp_audio_file, renamed_audio_file)
158
+
159
+ # temp_audio_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
160
+ # audio.export(temp_audio_file.name, format="mp3")
161
 
162
  # Rename the temporary audio file based on the text input
163
+ # global renamed_audio_file
164
+ # renamed_audio_file = os.path.join(tempfile.gettempdir(), f"{text_input}.mp3")
165
+ # os.rename(temp_audio_file.name, renamed_audio_file)
166
  if config["num_speakers"] > 1:
167
  speaker_selection.options = config["speaker_id_map"].values()
168
  speaker_selection.layout.visibility = 'visible'
 
223
 
224
 
225
  # Save the audio as a temporary WAV file
226
+ return templates.TemplateResponse("interface.html", {"request": request, "audio_file": renamed_audio_file, "data": data})
227
 
228
 
229
  # return {"message": f"Text to synthesize: {text_input}, Speed: {speed_slider}, Play: {play}"}