amir22010 commited on
Commit
9fac6ec
·
verified ·
1 Parent(s): 5db4b55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -28,16 +28,19 @@ for name in list_repo_files(repo_id="balacoon/tts"):
28
 
29
  def text_to_speech(text):
30
  with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_file:
 
 
 
 
 
31
  with locker:
32
- tts = TTS(os.path.join(os.getcwd(), tts_model_str))
33
- if len(text) > 1024:
34
- # truncate the text
35
- text_str = text[:1024]
36
- else:
37
- text_str = text
38
- audio_data = tts.synthesize(text_str, "92")
39
- temp_file.write(np.ascontiguousarray(audio_data))
40
- return temp_file.name
41
 
42
  def combine_audio_files(audio_files):
43
  combined = AudioSegment.empty()
 
28
 
29
  def text_to_speech(text):
30
  with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_file:
31
+ if len(text) > 1024:
32
+ # truncate the text
33
+ text_str = text[:1024]
34
+ else:
35
+ text_str = text
36
  with locker:
37
+ samples = tts.synthesize(text_str, "92")
38
+ output_file = temp_file.name
39
+ with wave.open(f"{output_file}", "w") as fp:
40
+ fp.setparams((1, 2, tts.get_sampling_rate(), len(samples), "NONE", "NONE"))
41
+ samples = np.ascontiguousarray(samples)
42
+ fp.writeframes(samples)
43
+ return output_file
 
 
44
 
45
  def combine_audio_files(audio_files):
46
  combined = AudioSegment.empty()