Veena commited on
Commit
ab22398
·
1 Parent(s): e5b76b7

Update Maya1 Gradio app with preset characters

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -194,20 +194,23 @@ def generate_speech(preset_name, description, text, temperature, max_tokens):
194
  if len(audio) > 2048:
195
  audio = audio[2048:]
196
 
197
- # Convert to WAV
 
 
 
198
  audio_int16 = (audio * 32767).astype(np.int16)
199
- wav_buffer = io.BytesIO()
200
- with wave.open(wav_buffer, 'wb') as wav_file:
201
- wav_file.setnchannels(1)
202
- wav_file.setsampwidth(2)
203
- wav_file.setframerate(AUDIO_SAMPLE_RATE)
204
- wav_file.writeframes(audio_int16.tobytes())
205
 
206
- wav_buffer.seek(0)
207
- duration = len(audio) / AUDIO_SAMPLE_RATE
 
 
 
 
208
 
 
209
  status_msg = f"Generated {duration:.2f}s of emotional speech!"
210
- return wav_buffer, status_msg
 
211
 
212
  except Exception as e:
213
  import traceback
 
194
  if len(audio) > 2048:
195
  audio = audio[2048:]
196
 
197
+ # Convert to WAV and save to temporary file
198
+ import tempfile
199
+ import soundfile as sf
200
+
201
  audio_int16 = (audio * 32767).astype(np.int16)
 
 
 
 
 
 
202
 
203
+ # Create temporary file
204
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as tmp_file:
205
+ tmp_path = tmp_file.name
206
+
207
+ # Save audio
208
+ sf.write(tmp_path, audio_int16, AUDIO_SAMPLE_RATE)
209
 
210
+ duration = len(audio) / AUDIO_SAMPLE_RATE
211
  status_msg = f"Generated {duration:.2f}s of emotional speech!"
212
+
213
+ return tmp_path, status_msg
214
 
215
  except Exception as e:
216
  import traceback