Mbonea commited on
Commit
97ddf7f
·
1 Parent(s): e2384ee

convert them to wav

Browse files
Files changed (1) hide show
  1. App/TTS/utils/Descript.py +12 -1
App/TTS/utils/Descript.py CHANGED
@@ -211,7 +211,7 @@ class DescriptTTS:
211
 
212
  def calculate_audio_duration(self, audio_file):
213
  file_format = audio_file.split(".")[-1]
214
- temp_file = AudioSegment.from_file(audio_file, format=file_format)
215
  duration_in_seconds = str(float(len(temp_file) / 1000))
216
  return duration_in_seconds
217
 
@@ -301,6 +301,15 @@ class DescriptTTS:
301
  # Wait for 24 hours before the next refresh
302
  await asyncio.sleep(24 * 60 * 60)
303
 
 
 
 
 
 
 
 
 
 
304
  async def update_refresh_token(self, new_refresh_token):
305
  # Update the new refresh token to Firebase
306
  data = {"refresh_token": new_refresh_token}
@@ -393,6 +402,8 @@ class DescriptTTS:
393
  audio_path = self.concatenate_wave_files(audio_paths)
394
  else:
395
  audio_path = audio_paths[0]
 
 
396
  data.add_field("audio", open(audio_path, "rb"))
397
 
398
  data.add_field("text", query.text)
 
211
 
212
  def calculate_audio_duration(self, audio_file):
213
  file_format = audio_file.split(".")[-1]
214
+ temp_file = AudioSegment.from_file(audio_file)
215
  duration_in_seconds = str(float(len(temp_file) / 1000))
216
  return duration_in_seconds
217
 
 
301
  # Wait for 24 hours before the next refresh
302
  await asyncio.sleep(24 * 60 * 60)
303
 
304
+ def convert_mp3_to_wav(mp3_path, wav_path):
305
+ # Load the MP3 file
306
+ audio = AudioSegment.from_mp3(mp3_path)
307
+
308
+ # Export the audio file in WAV format
309
+ audio.export(wav_path, format="wav")
310
+
311
+ return wav_path
312
+
313
  async def update_refresh_token(self, new_refresh_token):
314
  # Update the new refresh token to Firebase
315
  data = {"refresh_token": new_refresh_token}
 
402
  audio_path = self.concatenate_wave_files(audio_paths)
403
  else:
404
  audio_path = audio_paths[0]
405
+ wave_path = audio_path.split(".")[0] + ".wav"
406
+ audio_path = self.convert_mp3_to_wav(audio_path, wav_path=wave_path)
407
  data.add_field("audio", open(audio_path, "rb"))
408
 
409
  data.add_field("text", query.text)