Neomindapp commited on
Commit
44922b9
·
verified ·
1 Parent(s): e0ebb76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -1,20 +1,27 @@
1
  import gradio as gr
2
- import torch
3
- from coqui_tts import TTS # Adjust if there are specific classes for Coqui TTS
4
- import json
 
 
5
 
6
- # Load the Coqui TTS model and configuration
7
- model_path = "best_model.pth" # Directory where the model is saved
8
- config_path = "config.json"
9
 
10
- # Initialize TTS with your model and configuration
11
- tts = TTS(model_path=model_path, config_path=config_path)
 
12
 
13
  def generate_speech(text):
14
  # Generate speech using the model
15
- audio_path = tts.tts_to_file(text, "output.wav")
16
-
17
- # Load the generated audio file
 
 
 
 
18
  with open(audio_path, "rb") as f:
19
  audio_data = f.read()
20
 
 
1
  import gradio as gr
2
+ from TTS.utils.generic_utils import download_model
3
+ from TTS.utils.io import load_config
4
+ from TTS import TTS
5
+ import numpy as np
6
+ import soundfile as sf
7
 
8
+ # Define paths to the model and configuration
9
+ model_path = "best_model.pth" # Directory where your model is saved
10
+ config_path = "config.json" # Configuration file
11
 
12
+ # Load the model
13
+ config = load_config(config_path)
14
+ tts = TTS(config, model_path=model_path)
15
 
16
  def generate_speech(text):
17
  # Generate speech using the model
18
+ wav = tts.synthesize(text)
19
+
20
+ # Save the generated audio to a temporary file
21
+ audio_path = "output.wav"
22
+ sf.write(audio_path, wav, tts.sampling_rate)
23
+
24
+ # Read the audio file to return as binary data
25
  with open(audio_path, "rb") as f:
26
  audio_data = f.read()
27