amir22010 commited on
Commit
abd2b7a
·
verified ·
1 Parent(s): 95067e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -3,7 +3,7 @@ from llama_cpp import Llama
3
  import os
4
  from groq import Groq
5
  import numpy as np
6
- from scipy.io import wavfile
7
 
8
  #tts
9
  from balacoon_tts import TTS
@@ -47,10 +47,11 @@ llm = Llama.from_pretrained(
47
  def text_to_speech(text):
48
  with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_file:
49
  with locker:
50
- audio_data, sample_rate, *_ = tts.synthesize(text, "92")
51
- audio_data_int16 = (audio_data * 32767).astype(np.int16)
52
  output_file = temp_file.name
53
- wavfile.write(output_file, sample_rate, audio_data_int16)
 
 
54
  return output_file
55
 
56
 
 
3
  import os
4
  from groq import Groq
5
  import numpy as np
6
+ import wave
7
 
8
  #tts
9
  from balacoon_tts import TTS
 
47
  def text_to_speech(text):
48
  with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_file:
49
  with locker:
50
+ samples = tts.synthesize(text, "92")
 
51
  output_file = temp_file.name
52
+ with wave.open(f"{output_file}", "w") as fp:
53
+ fp.setparams((1, 2, tts.get_sampling_rate(), len(samples), "NONE", "NONE"))
54
+ fp.writeframes(samples)
55
  return output_file
56
 
57