Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
-
# Step 1:
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
import json
|
4 |
import torch
|
@@ -6,13 +9,13 @@ from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5Hif
|
|
6 |
from datasets import load_dataset
|
7 |
import soundfile as sf
|
8 |
|
9 |
-
# Step
|
10 |
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
11 |
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
|
12 |
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
13 |
|
14 |
# Load pronunciation dictionary from JSON file
|
15 |
-
with open("pronunciation_dict.json", "r") as f:
|
16 |
pronunciation_dict = json.load(f)
|
17 |
|
18 |
# Function to preprocess the input text
|
@@ -21,7 +24,7 @@ def preprocess_text(text):
|
|
21 |
text = text.replace(term, phonetic)
|
22 |
return text
|
23 |
|
24 |
-
# Step
|
25 |
def text_to_speech(input_text):
|
26 |
# Preprocess the text
|
27 |
processed_text = preprocess_text(input_text)
|
@@ -42,12 +45,12 @@ def text_to_speech(input_text):
|
|
42 |
|
43 |
return output_file
|
44 |
|
45 |
-
# Step
|
46 |
iface = gr.Interface(fn=text_to_speech,
|
47 |
inputs="text",
|
48 |
outputs="audio",
|
49 |
title="Text-to-Speech (TTS) Application",
|
50 |
description="Enter text with technical jargon for TTS conversion.")
|
51 |
|
52 |
-
# Step
|
53 |
iface.launch(share=True)
|
|
|
1 |
+
# Step 1: Install Gradio
|
2 |
+
!pip install gradio
|
3 |
+
|
4 |
+
# Step 2: Import necessary libraries
|
5 |
import gradio as gr
|
6 |
import json
|
7 |
import torch
|
|
|
9 |
from datasets import load_dataset
|
10 |
import soundfile as sf
|
11 |
|
12 |
+
# Step 3: Load the models and the pronunciation dictionary
|
13 |
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
14 |
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
|
15 |
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
16 |
|
17 |
# Load pronunciation dictionary from JSON file
|
18 |
+
with open("/content/pronunciation_dict (3) (1).json", "r") as f:
|
19 |
pronunciation_dict = json.load(f)
|
20 |
|
21 |
# Function to preprocess the input text
|
|
|
24 |
text = text.replace(term, phonetic)
|
25 |
return text
|
26 |
|
27 |
+
# Step 4: Define the TTS function
|
28 |
def text_to_speech(input_text):
|
29 |
# Preprocess the text
|
30 |
processed_text = preprocess_text(input_text)
|
|
|
45 |
|
46 |
return output_file
|
47 |
|
48 |
+
# Step 5: Create Gradio interface
|
49 |
iface = gr.Interface(fn=text_to_speech,
|
50 |
inputs="text",
|
51 |
outputs="audio",
|
52 |
title="Text-to-Speech (TTS) Application",
|
53 |
description="Enter text with technical jargon for TTS conversion.")
|
54 |
|
55 |
+
# Step 6: Launch the app
|
56 |
iface.launch(share=True)
|