unijoh commited on
Commit
bbe9b6e
1 Parent(s): 2f67968

Update tts.py

Browse files
Files changed (1) hide show
  1. tts.py +3 -1
tts.py CHANGED
@@ -3,6 +3,7 @@ from transformers import SpeechT5ForTextToSpeech, SpeechT5Processor
3
  import logging
4
  import numpy as np
5
  import soundfile as sf
 
6
 
7
  # Set up logging
8
  logging.basicConfig(level=logging.DEBUG)
@@ -31,7 +32,8 @@ def synthesize_speech(text):
31
 
32
  # Decode the generated speech and save to an audio file
33
  waveform = speech.cpu().numpy().flatten()
34
- sf.write("output.wav", waveform, 16000)
 
35
  logging.info("Audio file saved successfully.")
36
  return "output.wav"
37
  except Exception as e:
 
3
  import logging
4
  import numpy as np
5
  import soundfile as sf
6
+ import torchaudio
7
 
8
  # Set up logging
9
  logging.basicConfig(level=logging.DEBUG)
 
32
 
33
  # Decode the generated speech and save to an audio file
34
  waveform = speech.cpu().numpy().flatten()
35
+ # Use torchaudio to save the waveform
36
+ torchaudio.save("output.wav", torch.tensor(waveform).unsqueeze(0), 16000)
37
  logging.info("Audio file saved successfully.")
38
  return "output.wav"
39
  except Exception as e: