Mishmosh commited on
Commit
3b6e874
·
1 Parent(s): dc09336

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -8
app.py CHANGED
@@ -1,11 +1,30 @@
1
- # https://huggingface.co/spaces/Mishmosh/MichelleAssessment3
2
 
3
- # Install Rust
4
- #RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- #RUN python -m pip install --upgrade pip
7
- python -m pip install --upgrade pip
8
 
9
- #pip install --upgrade pip
10
- #RUN pip install --no-cache-dir -r requirements.txt
11
- #RUN pip install --use-feature=in-tree-build tokenizers
 
 
1
 
2
+ #text to speech
3
+ #!pip install git+https://github.com/huggingface/transformers.git
4
+ #!pip install datasets sentencepiece
5
+ import torch
6
+ import soundfile as sf
7
+ from IPython.display import Audio
8
+ from datasets import load_dataset
9
+ from transformers import pipeline
10
+ from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech
11
+ processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
12
+ model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
13
+ text = "The future belongs to those who believe in the beauty of their dreams."
14
+ #text = (summarized_text_list_list)
15
+
16
+ inputs = processor(text=summarized_text_list_list, return_tensors="pt")
17
+ from datasets import load_dataset
18
+ embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
19
+
20
+ import torch
21
+ speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
22
+ spectrogram = model.generate_speech(inputs["input_ids"], speaker_embeddings)
23
+ from transformers import SpeechT5HifiGan
24
+ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
25
+ with torch.no_grad():
26
+ speech = vocoder(spectrogram)
27
+ speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
28
+ Audio(speech, rate=16000)
29
 
 
 
30