ganga4364 commited on
Commit
a7f4b74
·
verified ·
1 Parent(s): f75de67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3
+ import scipy.io.wavfile
4
+ import numpy as np
5
+
6
+ # Load the MMS-TTS model and processor for Tibetan (bod)
7
+ model_id = "ganga4364/sherab-tts" # Replace with your fine-tuned model if necessary
8
+
9
+
10
+ # Use the text-to-speech pipeline with the model
11
+ synthesiser = pipeline("text-to-speech", model_id) # add device=0 if you want to use a GPU
12
+
13
+
14
+ # Function to perform TTS inference and save audio to a file
15
+ def generate_audio(input_text):
16
+ # Perform TTS inference
17
+ speech = synthesiser(input_text)
18
+ file_path = "finetuned_output.wav"
19
+ # Save the audio to a file (e.g., 'output.wav')
20
+ scipy.io.wavfile.write(file_path, rate=speech["sampling_rate"], data=speech["audio"][0])
21
+
22
+ # Return the path to the audio file
23
+ return file_path
24
+
25
+ # Create the Gradio interface
26
+ iface = gr.Interface(
27
+ fn=generate_audio,
28
+ inputs="text", # Text input for the TTS
29
+ outputs="audio", # Output will be an audio file
30
+ title="Tibetan Text-to-Speech (MMS-TTS)",
31
+ description="Enter Tibetan text and generate speech using MMS-TTS."
32
+ )
33
+
34
+ # Launch the Gradio interface
35
+ iface.launch()