Shanuka01 commited on
Commit
100749a
·
1 Parent(s): f6a7c4b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ from TTS.api import TTS
4
+ import gradio as gr
5
+ from TTS.tts.configs.xtts_config import XttsConfig
6
+ from TTS.tts.models.xtts import Xtts
7
+ from scipy.io.wavfile import write
8
+ import numpy as np
9
+ from transformers import pipeline
10
+
11
+
12
+
13
+ def tts_generate(text, speaker_wav="model2.mp3"):
14
+ # Get device
15
+ device = device = "cuda" if torch.cuda.is_available() else "cpu"
16
+
17
+ # Run TTS
18
+
19
+ asr = pipeline("Text-to-Speech", model="coqui/XTTS-v1")
20
+
21
+ # generate speech by cloning a voice using default settings
22
+ tts.tts_to_file(text=text, speaker_wav="voice_models/" + speaker_wav, language="en", file_path="output.wav")
23
+ return "output.wav"
24
+
25
+ def greet(name):
26
+ return "Hello " + name + "!!"
27
+
28
+ iface = gr.Interface(fn=tts_generate,
29
+ inputs=["text", "text"],
30
+ outputs=["audio"],
31
+ examples=[
32
+ ["Hello Jhon. Welcome to our group.", "model1.wav"],
33
+ ["Hello Jhon. Welcome to our group.", "model2.mp3"]]
34
+ )
35
+ iface.launch(share=True, debug=True)
36
+
37
+ # tts_generate("Hello Jhon. Welcome to our group.", "model2.mp3")