willsh1997 commited on
Commit
c3b86c9
·
1 Parent(s): 44173ee

:clown_face: streaming commit

Browse files
Files changed (3) hide show
  1. README.md +28 -2
  2. groq-voicechat-demo.py +7 -2
  3. kokoro_support.py +25 -9
README.md CHANGED
@@ -1,2 +1,28 @@
1
- # voicechat-demo
2
- quick voicechat demo with manual options for playback and input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ---
2
+
3
+ # title: Groq Voicechat Demo
4
+
5
+ # emoji: 💻
6
+
7
+ # colorFrom: indigo
8
+
9
+ # colorTo: pink
10
+
11
+ # sdk: gradio
12
+
13
+ # sdk\_version: 6.0.2
14
+
15
+ # app\_file: groq-voicechat-demo.py
16
+
17
+ # pinned: false
18
+
19
+ # license: gpl-3.0
20
+
21
+ # short\_description: llm backed voicechat with kokoro and whisper
22
+
23
+ # ---
24
+
25
+ #
26
+
27
+ # Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
28
+
groq-voicechat-demo.py CHANGED
@@ -133,7 +133,8 @@ def create_demo():
133
  audio_out = gr.Audio(
134
  label = "Output Audio",
135
  interactive = False,
136
- autoplay = True
 
137
  )
138
 
139
 
@@ -161,8 +162,12 @@ def create_demo():
161
  def playback_last_message(chat_history):
162
  if len(chat_history) > 0:
163
  last_message = chat_history[-1]['content'][0]['text']
164
- return generate_tts(last_message)
 
 
165
  return None
 
 
166
 
167
  playback_button.click(
168
  playback_last_message,
 
133
  audio_out = gr.Audio(
134
  label = "Output Audio",
135
  interactive = False,
136
+ autoplay = True,
137
+ streaming = True
138
  )
139
 
140
 
 
162
  def playback_last_message(chat_history):
163
  if len(chat_history) > 0:
164
  last_message = chat_history[-1]['content'][0]['text']
165
+ gen_object = generate_tts(last_message)
166
+ for chunk in gen_object:
167
+ yield chunk
168
  return None
169
+ # return generate_tts(last_message)
170
+ # return None
171
 
172
  playback_button.click(
173
  playback_last_message,
kokoro_support.py CHANGED
@@ -3,26 +3,42 @@ import os
3
  import random
4
  import numpy as np
5
  import kokoro
 
6
 
7
 
8
  model = KModel().to('cpu').eval()
9
  pipeline = KPipeline(lang_code='a', model=False)
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def generate_tts(text, voice='af_heart', speed=1):
12
  pack = pipeline.load_voice(voice)
13
- audio_chunks = []
14
  for _, ps, _ in pipeline(text, voice, speed):
15
  ref_s = pack[len(ps)-1]
16
  try:
17
  audio = model(ps, ref_s, speed)
18
- audio_chunks.append(audio.numpy())
19
  except:
20
  print("lol there was an issue idk")
21
- # yield 24000, audio.numpy()
22
- if audio_chunks:
23
- concatenated_audio = np.concatenate(audio_chunks)
24
- print(concatenated_audio.shape)
25
- return 24000, concatenated_audio
26
- else:
27
- return 24000, np.array([])
28
 
 
3
  import random
4
  import numpy as np
5
  import kokoro
6
+ import torch
7
 
8
 
9
  model = KModel().to('cpu').eval()
10
  pipeline = KPipeline(lang_code='a', model=False)
11
 
12
+ # def generate_tts(text, voice='af_heart', speed=1):
13
+ # pack = pipeline.load_voice(voice)
14
+ # audio_chunks = []
15
+ # for _, ps, _ in pipeline(text, voice, speed):
16
+ # ref_s = pack[len(ps)-1]
17
+ # try:
18
+ # audio = model(ps, ref_s, speed)
19
+ # audio_chunks.append(audio.numpy())
20
+ # except:
21
+ # print("lol there was an issue idk")
22
+ # # yield 24000, audio.numpy()
23
+ # if audio_chunks:
24
+ # concatenated_audio = np.concatenate(audio_chunks)
25
+ # print(concatenated_audio.shape)
26
+ # return 24000, concatenated_audio
27
+ # else:
28
+ # return 24000, np.array([])
29
+
30
+
31
  def generate_tts(text, voice='af_heart', speed=1):
32
  pack = pipeline.load_voice(voice)
33
+ first = True
34
  for _, ps, _ in pipeline(text, voice, speed):
35
  ref_s = pack[len(ps)-1]
36
  try:
37
  audio = model(ps, ref_s, speed)
 
38
  except:
39
  print("lol there was an issue idk")
40
+ yield 24000, audio.numpy()
41
+ if first:
42
+ first = False
43
+ yield 24000, torch.zeros(1).numpy()
 
 
 
44