Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,17 +27,14 @@ def guessanAge(model, image):
|
|
| 27 |
|
| 28 |
@spaces.GPU(duration=120)
|
| 29 |
def text2speech(model, text, voice):
|
| 30 |
-
print(
|
| 31 |
if len(text) > 0:
|
| 32 |
-
|
| 33 |
-
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
|
| 34 |
-
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
| 35 |
-
inputs = processor(text=text, return_tensors="pt")
|
| 36 |
|
| 37 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
| 38 |
speaker_embedding = torch.tensor(embeddings_dataset[voice]["xvector"]).unsqueeze(0)
|
| 39 |
|
| 40 |
-
speech =
|
| 41 |
audio_data = np.frombuffer(speech["audio"], dtype=np.float32)
|
| 42 |
audio_data_16bit = (audio_data * 32767).astype(np.int16)
|
| 43 |
return speech["sampling_rate"], audio_data_16bit
|
|
|
|
| 27 |
|
| 28 |
@spaces.GPU(duration=120)
|
| 29 |
def text2speech(model, text, voice):
|
| 30 |
+
print(voice)
|
| 31 |
if len(text) > 0:
|
| 32 |
+
synthesiser = pipeline("text-to-speech", model=model)
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
| 35 |
speaker_embedding = torch.tensor(embeddings_dataset[voice]["xvector"]).unsqueeze(0)
|
| 36 |
|
| 37 |
+
speech = synthesiser(text, forward_params={"speaker_embeddings": speaker_embedding})
|
| 38 |
audio_data = np.frombuffer(speech["audio"], dtype=np.float32)
|
| 39 |
audio_data_16bit = (audio_data * 32767).astype(np.int16)
|
| 40 |
return speech["sampling_rate"], audio_data_16bit
|