Akjava commited on
Commit
b1dda8a
·
verified ·
1 Parent(s): abb1cf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -2
app.py CHANGED
@@ -90,11 +90,71 @@ def call_generate_text(message, history):
90
  return "",history
91
 
92
 
93
- with gr.Blocks(title="LLM with TTS") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  gr.Markdown("LLM and TTS models will change without notice.")
95
  js = """
96
  function(chatbot){
97
- console.log(chatbot[chatbot.length -1])
 
98
  }
99
  """
100
  chatbot = gr.Chatbot(type="messages")
 
90
  return "",history
91
 
92
 
93
+
94
+ head = '''
95
+ <script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.webgpu.min.js" ></script>
96
+
97
+ <script type="module">
98
+
99
+ import { MatchaTTSRaw } from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/matcha_tts_raw.js";
100
+ import { webWavPlay } from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/web_wav_play.js";
101
+ import { arpa_to_ipa } from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/arpa_to_ipa.js";
102
+ import { loadCmudict } from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/cmudict_loader.js";
103
+ import { env,textToArpa} from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/text_to_arpa.js";
104
+
105
+ env.allowLocalModels = true;
106
+ env.localModelPath = "./models/";
107
+ env.backends.onnx.logLevel = "fatal";
108
+
109
+ let matcha_tts_raw;
110
+ let cmudict ={};
111
+ let speaking = false;
112
+ async function main(text,speed=1.0,tempature=0.5,spk=0) {
113
+ console.log(text)
114
+ if (speaking){
115
+ console.log("speaking return")
116
+ }
117
+ speaking = true
118
+ console.log("main called")
119
+ if(!matcha_tts_raw){
120
+ matcha_tts_raw = new MatchaTTSRaw()
121
+ console.time("load model");
122
+ await matcha_tts_raw.load_model('https://huggingface.co/spaces/Akjava/matcha-tts-onnx-benchmarks/resolve/main/models/matcha-tts/ljspeech_sim.onnx',{ executionProviders: ['webgpu','wasm'] });
123
+
124
+ console.timeEnd("load model");
125
+
126
+ let cmudictReady = loadCmudict(cmudict,'https://akjava.github.io/Matcha-TTS-Japanese/dictionaries/cmudict-0.7b')
127
+ await cmudictReady
128
+ }else{
129
+ console.log("session exist skip load model")
130
+ }
131
+
132
+ const arpa_text = await textToArpa(cmudict,text)
133
+ const ipa_text = arpa_to_ipa(arpa_text).replace(/\s/g, "");
134
+ console.log(ipa_text)
135
+ const spks = 0
136
+
137
+ console.time("infer");
138
+ const result = await matcha_tts_raw.infer(ipa_text, tempature, speed,spks);
139
+
140
+ if (result!=null){
141
+ console.timeEnd("infer");
142
+ webWavPlay(result)
143
+
144
+ }
145
+
146
+ speaking = false
147
+ }
148
+ window.MatchaTTSEn = main
149
+ console.log(MatchaTTSRaw)
150
+ </script>
151
+ '''
152
+ with gr.Blocks(title="LLM with TTS",head=head) as demo:
153
  gr.Markdown("LLM and TTS models will change without notice.")
154
  js = """
155
  function(chatbot){
156
+ text = (chatbot[chatbot.length -1])["content"]
157
+ window.MatchaTTSEn(text)
158
  }
159
  """
160
  chatbot = gr.Chatbot(type="messages")