Spaces:
Runtime error
Runtime error
AudreyMireille
commited on
Commit
•
7e5800b
1
Parent(s):
824cbde
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
from datasets import load_dataset
|
3 |
+
import soundfile as sf
|
4 |
+
import torch
|
5 |
+
synthetiser =pipeline('text-to-speech', model='microsoft/speecht5_tts')
|
6 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
7 |
+
speaker_embedding = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
8 |
+
speech = synthetiser("Hello everyone!", forward_params={"speaker_embeddings": speaker_embedding})
|
9 |
+
sf.write("speech.wav", speech["audio"], samplerate=speech["sampling_rate"])
|
10 |
+
|
11 |
+
import gradio as gr
|
12 |
+
def text_to_speech(text):
|
13 |
+
speech = synthetiser(text)
|
14 |
+
return(speech['audio'])
|
15 |
+
|
16 |
+
demo_text_to_speech = gr.Interface(text_to_speech, title="Text to speech converter", description="Enter a text here!", inputs='text', outputs='audio')
|
17 |
+
demo_text_to_speech.launch()
|