Akjava commited on
Commit
9224f10
·
1 Parent(s): 0585512

tts-stream

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -10,9 +10,10 @@ def generate_text(messages):
10
  for token in client.chat_completion(messages, max_tokens=50,stream=True):
11
  content = (token.choices[0].delta.content)
12
  generated+=content
13
- print(generated)
 
14
 
15
- return generated #no stram version
16
 
17
  def call_generate_text(message, history):
18
  #if len(message) == 0:
@@ -36,16 +37,24 @@ def call_generate_text(message, history):
36
  head = '''
37
  <script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.webgpu.min.js" ></script>
38
  <script type="module">
39
- import { matcha_tts,env } from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/v001-20240921/matcha_tts_onnx_en.js";
40
  window.MatchaTTSEn = matcha_tts
 
 
 
 
 
 
41
  </script>
42
 
43
  <script>
 
44
  let last_chatbot_size = 0
45
  let tts_text_index = 0
46
  let tts_texts = []
47
 
48
- const interval = 100
 
49
  async function start_multi_line_tts() {
50
  //console.log("start_multi_line_tts")
51
  //console.log(tts_texts.length)
@@ -54,7 +63,9 @@ async function start_multi_line_tts() {
54
  tts_text_index += 1
55
  console.log(tts_text)
56
  if (tts_text!=""){
 
57
  await window.MatchaTTSEn(tts_text,"/file=models/ljspeech_sim.onnx")
 
58
  }
59
 
60
 
@@ -64,7 +75,11 @@ async function start_multi_line_tts() {
64
 
65
 
66
  function reset_tts_text(){
67
- console.log("reset tts text")
 
 
 
 
68
  tts_text_index = 0
69
  tts_texts = []
70
  }
@@ -86,7 +101,7 @@ function update_tts_texts(text){
86
  if (value.endsWith(".") || value.endsWith("?") || value.endsWith("!")){
87
  new_texts.push(value);
88
  }
89
- console.log("Last element:", value);
90
  } else {
91
  // その他の要素に対する処理
92
  new_texts.push(value);
@@ -112,7 +127,7 @@ window.replaceSpecialChars = replaceSpecialChars
112
  window.update_chatbot = update_chatbot
113
  window.update_tts_texts = update_tts_texts
114
  window.reset_tts_text = reset_tts_text
115
- start_multi_line_tts();
116
  </script>
117
  '''
118
 
 
10
  for token in client.chat_completion(messages, max_tokens=50,stream=True):
11
  content = (token.choices[0].delta.content)
12
  generated+=content
13
+ #yield generated
14
+ #print(token.choices[0].delta)
15
 
16
+ return generated+"." #no stram version
17
 
18
  def call_generate_text(message, history):
19
  #if len(message) == 0:
 
37
  head = '''
38
  <script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.webgpu.min.js" ></script>
39
  <script type="module">
40
+ import { matcha_tts,env ,start_thread_play_tts} from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/matcha_tts_onnx_en.js";
41
  window.MatchaTTSEn = matcha_tts
42
+ window.start_threads = async function(){
43
+ //sadly onload unstable
44
+ //console.log("start_threads")
45
+ await start_thread_play_tts();
46
+ await start_multi_line_tts();
47
+ }
48
  </script>
49
 
50
  <script>
51
+ let is_start_threads = false
52
  let last_chatbot_size = 0
53
  let tts_text_index = 0
54
  let tts_texts = []
55
 
56
+ const interval = 10
57
+
58
  async function start_multi_line_tts() {
59
  //console.log("start_multi_line_tts")
60
  //console.log(tts_texts.length)
 
63
  tts_text_index += 1
64
  console.log(tts_text)
65
  if (tts_text!=""){
66
+ //console.log("statar await load")
67
  await window.MatchaTTSEn(tts_text,"/file=models/ljspeech_sim.onnx")
68
+ //console.log("end await ")
69
  }
70
 
71
 
 
75
 
76
 
77
  function reset_tts_text(){
78
+ if (is_start_threads == false){
79
+ window.start_threads()
80
+ is_start_threads = true
81
+ }
82
+ console.log("new messages")
83
  tts_text_index = 0
84
  tts_texts = []
85
  }
 
101
  if (value.endsWith(".") || value.endsWith("?") || value.endsWith("!")){
102
  new_texts.push(value);
103
  }
104
+ //console.log("Last element:", value);
105
  } else {
106
  // その他の要素に対する処理
107
  new_texts.push(value);
 
127
  window.update_chatbot = update_chatbot
128
  window.update_tts_texts = update_tts_texts
129
  window.reset_tts_text = reset_tts_text
130
+
131
  </script>
132
  '''
133