shiveshnavin commited on
Commit
8c33263
·
1 Parent(s): 617d161

Fixed Audio output

Browse files
Files changed (4) hide show
  1. .gitignore +2 -1
  2. app.py +7 -3
  3. output.wav +0 -0
  4. requirements.txt +2 -1
.gitignore CHANGED
@@ -1 +1,2 @@
1
- flagged/
 
 
1
+ flagged/
2
+ *.wav
app.py CHANGED
@@ -2,6 +2,9 @@ import gradio as gr
2
  from TTS.api import TTS
3
  import tempfile
4
  import os
 
 
 
5
 
6
  model_name = "tts_models/en/vctk/vits"
7
  promisingM = ["p282", "p301", "p234", "p232", "p256", "p267", "p272"]
@@ -24,9 +27,10 @@ def text_to_speech(sentence, speaker_name):
24
  wav = tts.tts_to_file(
25
  text=sentence, speaker=speaker_name, file_path=file, verbose=False
26
  )
27
- with open(wav, "rb") as audio_file:
28
- audio_data = audio_file.read()
29
- return wav
 
30
 
31
 
32
  iface = gr.Interface(
 
2
  from TTS.api import TTS
3
  import tempfile
4
  import os
5
+ import soundfile as sf
6
+ import numpy as np
7
+
8
 
9
  model_name = "tts_models/en/vctk/vits"
10
  promisingM = ["p282", "p301", "p234", "p232", "p256", "p267", "p272"]
 
27
  wav = tts.tts_to_file(
28
  text=sentence, speaker=speaker_name, file_path=file, verbose=False
29
  )
30
+ audio, sample_rate = sf.read(wav, dtype="float32")
31
+ audio_bytes = (audio * 32767).astype(np.int16)
32
+ os.remove(wav)
33
+ return sample_rate, audio_bytes
34
 
35
 
36
  iface = gr.Interface(
output.wav DELETED
File without changes
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  gradio==3.38.0
2
  TTS==0.15.6
3
  numpy==1.22.0;python_version<="3.10"
4
- numpy==1.24.3;python_version>"3.10"
 
 
1
  gradio==3.38.0
2
  TTS==0.15.6
3
  numpy==1.22.0;python_version<="3.10"
4
+ numpy==1.24.3;python_version>"3.10"
5
+ soundfile