hashhac commited on
Commit
58bcff1
·
1 Parent(s): 3f38c72

float coinversion therpy

Browse files
Files changed (1) hide show
  1. app.py +3 -1
app.py CHANGED
@@ -104,9 +104,11 @@ def text_to_speech(text):
104
  # Make sure speech is float32 before any conversion to avoid the error
105
  audio_array = speech.cpu().numpy().astype(np.float32)
106
 
 
 
107
 
108
  # Reshape for fastrtc
109
- audio_array = audio_array.reshape(1, -1)
110
 
111
  return (16000, audio_array) # SpeechT5 uses 16kHz sample rate
112
 
 
104
  # Make sure speech is float32 before any conversion to avoid the error
105
  audio_array = speech.cpu().numpy().astype(np.float32)
106
 
107
+ # Normalize and convert to int16 for output
108
+ audio_array = (audio_array / np.max(np.abs(audio_array) + 1e-6) * 32767).astype(np.int16)
109
 
110
  # Reshape for fastrtc
111
+ audio_array = audio_array.reshape(1, -1).astype(np.float32)
112
 
113
  return (16000, audio_array) # SpeechT5 uses 16kHz sample rate
114