reach-vb HF Staff commited on
Commit
47e9afc
·
1 Parent(s): 1c9d7f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -9,6 +9,7 @@ from TTS.utils.generic_utils import get_user_data_dir
9
 
10
  import gradio as gr
11
  from scipy.io.wavfile import write
 
12
 
13
  os.environ["COQUI_TOS_AGREED"] = "1"
14
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v1")
@@ -40,11 +41,11 @@ def stream_audio(synthesis_text):
40
 
41
  for i, chunk in enumerate(chunks):
42
  print(f"Received chunk {i} of audio length {chunk.shape[-1]}")
43
- bytes_wav = bytes()
44
- byte_io = io.BytesIO(bytes_wav)
45
- write(byte_io, 24000, chunk.detach().cpu().numpy().squeeze())
46
- result_bytes = byte_io.read()
47
- yield result_bytes
48
 
49
  demo = gr.Interface(
50
  fn=stream_audio,
 
9
 
10
  import gradio as gr
11
  from scipy.io.wavfile import write
12
+ from pydub import AudioSegment
13
 
14
  os.environ["COQUI_TOS_AGREED"] = "1"
15
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v1")
 
41
 
42
  for i, chunk in enumerate(chunks):
43
  print(f"Received chunk {i} of audio length {chunk.shape[-1]}")
44
+ out_file = f'{i}.wav'
45
+ write(out_file, 24000, chunk.detach().cpu().numpy().squeeze())
46
+ audio = AudioSegment.from_file(out_file)
47
+ audio.export(out_file, format='wav')
48
+ yield out_file
49
 
50
  demo = gr.Interface(
51
  fn=stream_audio,