rutsam commited on
Commit
761c6e2
·
1 Parent(s): a33e730

return engine

Browse files
Files changed (2) hide show
  1. app.py +2 -17
  2. engine.py +24 -0
app.py CHANGED
@@ -1,20 +1,11 @@
1
  import tempfile
2
  from typing import Optional
3
  import gradio as gr
4
- import numpy as np
5
- from TTS.api import TTS
6
- from huggingface_hub import hf_hub_download
7
  import subprocess
8
 
9
 
10
  MAX_TXT_LEN = 100
11
- REPO_NAME="DigitalUmuganda/Kinyarwanda_YourTTS"
12
- hf_hub_download(repo_id=REPO_NAME,filename="config.json")
13
- hf_hub_download(repo_id=REPO_NAME,filename="SE_checkpoint.pth.tar")
14
- hf_hub_download(repo_id=REPO_NAME,filename="config_se.json")
15
- hf_hub_download(repo_id=REPO_NAME,filename="model.pth")
16
- hf_hub_download(repo_id=REPO_NAME,filename="speakers.pth")
17
- hf_hub_download(repo_id=REPO_NAME,filename="conditioning_audio.wav")
18
 
19
  def generate_audio(text):
20
  if len(text) > MAX_TXT_LEN:
@@ -31,13 +22,7 @@ def generate_audio(text):
31
  # )
32
  # if synthesizer is None:
33
  # raise NameError("model not found")
34
- # tts = TTS(model_path="Kinyarwanda_YourTTS/model.pth",
35
- # config_path="Kinyarwanda_YourTTS/config.json",
36
- # tts_speakers_file="Kinyarwanda_YourTTS/speakers.pth",
37
- # encoder_checkpoint="Kinyarwanda_YourTTS/SE_checkpoint.pth.tar",
38
- # encoder_config="Kinyarwanda_YourTTS/config_se.json",)
39
- # wav = tts.tts(text, speaker_wav="kinyarwanda_YourTTS/conditioning_audio.wav")
40
- # return wav
41
  text1 = subprocess.check_output("ls", shell=True)+ subprocess.check_output("ls", shell=True)
42
  text2 = text1.decode("utf-8")
43
  return text2
 
1
  import tempfile
2
  from typing import Optional
3
  import gradio as gr
4
+ from engine import TextToSpeech
 
 
5
  import subprocess
6
 
7
 
8
  MAX_TXT_LEN = 100
 
 
 
 
 
 
 
9
 
10
  def generate_audio(text):
11
  if len(text) > MAX_TXT_LEN:
 
22
  # )
23
  # if synthesizer is None:
24
  # raise NameError("model not found")
25
+ tts_engine= TextToSpeech()
 
 
 
 
 
 
26
  text1 = subprocess.check_output("ls", shell=True)+ subprocess.check_output("ls", shell=True)
27
  text2 = text1.decode("utf-8")
28
  return text2
engine.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from TTS.api import TTS
3
+ from huggingface_hub import hf_hub_download
4
+ import subprocess
5
+
6
+ REPO_NAME="DigitalUmuganda/Kinyarwanda_YourTTS"
7
+ class TextToSpeech():
8
+
9
+ def __init__(self) -> None:
10
+ hf_hub_download(repo_id=REPO_NAME,filename="config.json")
11
+ hf_hub_download(repo_id=REPO_NAME,filename="SE_checkpoint.pth.tar")
12
+ hf_hub_download(repo_id=REPO_NAME,filename="config_se.json")
13
+ hf_hub_download(repo_id=REPO_NAME,filename="model.pth")
14
+ hf_hub_download(repo_id=REPO_NAME,filename="speakers.pth")
15
+ hf_hub_download(repo_id=REPO_NAME,filename="conditioning_audio.wav")
16
+
17
+ def run_tts(self,text):
18
+ tts = TTS(model_path="Kinyarwanda_YourTTS/model.pth",
19
+ config_path="Kinyarwanda_YourTTS/config.json",
20
+ tts_speakers_file="Kinyarwanda_YourTTS/speakers.pth",
21
+ encoder_checkpoint="Kinyarwanda_YourTTS/SE_checkpoint.pth.tar",
22
+ encoder_config="Kinyarwanda_YourTTS/config_se.json",)
23
+ wav = tts.tts(text, speaker_wav="kinyarwanda_YourTTS/conditioning_audio.wav")
24
+ return wav