Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -275,5 +275,35 @@ print(summarized_text)
|
|
275 |
# number_of_sentences-=1
|
276 |
#print(summarized_text_list_list)
|
277 |
#print(number_of_sentences)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
|
279 |
|
|
|
275 |
# number_of_sentences-=1
|
276 |
#print(summarized_text_list_list)
|
277 |
#print(number_of_sentences)
|
278 |
+
#text to speech
|
279 |
+
#!pip install git+https://github.com/huggingface/transformers.git
|
280 |
+
#!pip install datasets sentencepiece
|
281 |
+
import torch
|
282 |
+
import soundfile as sf
|
283 |
+
from IPython.display import Audio
|
284 |
+
from datasets import load_dataset
|
285 |
+
from transformers import pipeline
|
286 |
+
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech
|
287 |
+
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
288 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
|
289 |
+
text = "The future belongs to those who believe in the beauty of their dreams."
|
290 |
+
#text = (summarized_text_list_list)
|
291 |
+
|
292 |
+
#inputs = processor(text=summarized_text_list_list, return_tensors="pt")
|
293 |
+
inputs = processor(text, return_tensors="pt")
|
294 |
+
from datasets import load_dataset
|
295 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
296 |
+
|
297 |
+
import torch
|
298 |
+
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
299 |
+
spectrogram = model.generate_speech(inputs["input_ids"], speaker_embeddings)
|
300 |
+
from transformers import SpeechT5HifiGan
|
301 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
302 |
+
with torch.no_grad():
|
303 |
+
speech = vocoder(spectrogram)
|
304 |
+
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
305 |
+
Audio(speech, rate=16000)
|
306 |
+
|
307 |
+
|
308 |
|
309 |
|