Neomindapp commited on
Commit
7a21455
·
verified ·
1 Parent(s): f8eeedf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -1,25 +1,22 @@
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:
 
1
  import gradio as gr
2
+ import torch
3
+ from TTS.api import TTS # Correct import path for TTS API
 
 
 
4
 
5
  # Define paths to the model and configuration
6
  model_path = "best_model.pth" # Directory where your model is saved
7
  config_path = "config.json" # Configuration file
8
 
9
+ # Initialize TTS with your model and configuration
10
+ tts = TTS(model_path=model_path, config_path=config_path)
 
11
 
12
  def generate_speech(text):
13
  # Generate speech using the model
14
+ wav = tts.tts(text)
15
 
16
  # Save the generated audio to a temporary file
17
  audio_path = "output.wav"
18
+ with open(audio_path, "wb") as f:
19
+ f.write(wav)
20
 
21
  # Read the audio file to return as binary data
22
  with open(audio_path, "rb") as f: