Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,60 +93,9 @@ def call_generate_text(message, history):
|
|
| 93 |
|
| 94 |
head = '''
|
| 95 |
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.webgpu.min.js" ></script>
|
| 96 |
-
|
| 97 |
-
|
| 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 = "https://akjava.github.io/Matcha-TTS-Japanese/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:
|
|
|
|
| 93 |
|
| 94 |
head = '''
|
| 95 |
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.webgpu.min.js" ></script>
|
| 96 |
+
<script type="module">
|
| 97 |
+
import { matcha_tts,env } from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/matcha_tts_onnx_en_dev.js";
|
| 98 |
+
window.MatchaTTSEn = matcha_tts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
</script>
|
| 100 |
'''
|
| 101 |
with gr.Blocks(title="LLM with TTS",head=head) as demo:
|