Spaces:
Running
Running
Commit ยท
3da71e7
1
Parent(s): c3b86c9
:clown_face: please work
Browse files- groq-voicechat-demo.py +16 -20
- kokoro_support.py +34 -18
groq-voicechat-demo.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
from groq import Groq
|
| 3 |
import os
|
| 4 |
from whisper_support import transcribe
|
| 5 |
-
from kokoro_support import generate_tts
|
| 6 |
|
| 7 |
groq_api_key = os.environ.get("GROQ_API_KEY")
|
| 8 |
|
|
@@ -129,6 +129,18 @@ def create_demo():
|
|
| 129 |
|
| 130 |
with gr.Row():
|
| 131 |
playback_button = gr.Button("playback last message")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
with gr.Row():
|
| 133 |
audio_out = gr.Audio(
|
| 134 |
label = "Output Audio",
|
|
@@ -136,22 +148,6 @@ def create_demo():
|
|
| 136 |
autoplay = True,
|
| 137 |
streaming = True
|
| 138 |
)
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
# stream = voiceinput.start_recording(
|
| 143 |
-
# process_audio,
|
| 144 |
-
# [voiceinput],
|
| 145 |
-
# [voiceinput],
|
| 146 |
-
# )
|
| 147 |
-
# respond = voiceinput.stop_recording(
|
| 148 |
-
# groq_voicechat,
|
| 149 |
-
# [voiceinput, chatbot, model, system_prompt, ],
|
| 150 |
-
# [chatbot]
|
| 151 |
-
# )
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
|
| 156 |
output = voiceinput.stop_recording(
|
| 157 |
groq_voicechat,
|
|
@@ -159,10 +155,10 @@ def create_demo():
|
|
| 159 |
[chatbot]
|
| 160 |
) #WHAT AM I DOING LOL - COME BACK TO THIS
|
| 161 |
|
| 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
|
|
@@ -171,7 +167,7 @@ def create_demo():
|
|
| 171 |
|
| 172 |
playback_button.click(
|
| 173 |
playback_last_message,
|
| 174 |
-
inputs=[chatbot],
|
| 175 |
outputs=[audio_out]
|
| 176 |
)
|
| 177 |
|
|
|
|
| 2 |
from groq import Groq
|
| 3 |
import os
|
| 4 |
from whisper_support import transcribe
|
| 5 |
+
from kokoro_support import generate_tts, voice_choices
|
| 6 |
|
| 7 |
groq_api_key = os.environ.get("GROQ_API_KEY")
|
| 8 |
|
|
|
|
| 129 |
|
| 130 |
with gr.Row():
|
| 131 |
playback_button = gr.Button("playback last message")
|
| 132 |
+
with gr.Row():
|
| 133 |
+
voice_opps = gr.Dropdown(
|
| 134 |
+
choices = list(voice_choices.keys()),
|
| 135 |
+
value = list(voice_choices.keys())[0]
|
| 136 |
+
)
|
| 137 |
+
with gr.Row():
|
| 138 |
+
voice_speed = gr.Slider(
|
| 139 |
+
minimum = 0.5,
|
| 140 |
+
maximum = 2,
|
| 141 |
+
value = 1,
|
| 142 |
+
step = 0.1,
|
| 143 |
+
)
|
| 144 |
with gr.Row():
|
| 145 |
audio_out = gr.Audio(
|
| 146 |
label = "Output Audio",
|
|
|
|
| 148 |
autoplay = True,
|
| 149 |
streaming = True
|
| 150 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
output = voiceinput.stop_recording(
|
| 153 |
groq_voicechat,
|
|
|
|
| 155 |
[chatbot]
|
| 156 |
) #WHAT AM I DOING LOL - COME BACK TO THIS
|
| 157 |
|
| 158 |
+
def playback_last_message(chat_history, voice, speed):
|
| 159 |
if len(chat_history) > 0:
|
| 160 |
last_message = chat_history[-1]['content'][0]['text']
|
| 161 |
+
gen_object = generate_tts(last_message, voice_choices[voice], speed)
|
| 162 |
for chunk in gen_object:
|
| 163 |
yield chunk
|
| 164 |
return None
|
|
|
|
| 167 |
|
| 168 |
playback_button.click(
|
| 169 |
playback_last_message,
|
| 170 |
+
inputs=[chatbot, voice_opps, voice_speed],
|
| 171 |
outputs=[audio_out]
|
| 172 |
)
|
| 173 |
|
kokoro_support.py
CHANGED
|
@@ -5,30 +5,46 @@ 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):
|
|
|
|
| 5 |
import kokoro
|
| 6 |
import torch
|
| 7 |
|
| 8 |
+
voice_choices = {
|
| 9 |
+
'๐บ๐ธ ๐บ Heart โค๏ธ': 'af_heart',
|
| 10 |
+
'๐บ๐ธ ๐บ Bella ๐ฅ': 'af_bella',
|
| 11 |
+
'๐บ๐ธ ๐บ Nicole ๐ง': 'af_nicole',
|
| 12 |
+
'๐บ๐ธ ๐บ Aoede': 'af_aoede',
|
| 13 |
+
'๐บ๐ธ ๐บ Kore': 'af_kore',
|
| 14 |
+
'๐บ๐ธ ๐บ Sarah': 'af_sarah',
|
| 15 |
+
'๐บ๐ธ ๐บ Nova': 'af_nova',
|
| 16 |
+
'๐บ๐ธ ๐บ Sky': 'af_sky',
|
| 17 |
+
'๐บ๐ธ ๐บ Alloy': 'af_alloy',
|
| 18 |
+
'๐บ๐ธ ๐บ Jessica': 'af_jessica',
|
| 19 |
+
'๐บ๐ธ ๐บ River': 'af_river',
|
| 20 |
+
'๐บ๐ธ ๐น Michael': 'am_michael',
|
| 21 |
+
'๐บ๐ธ ๐น Fenrir': 'am_fenrir',
|
| 22 |
+
'๐บ๐ธ ๐น Puck': 'am_puck',
|
| 23 |
+
'๐บ๐ธ ๐น Echo': 'am_echo',
|
| 24 |
+
'๐บ๐ธ ๐น Eric': 'am_eric',
|
| 25 |
+
'๐บ๐ธ ๐น Liam': 'am_liam',
|
| 26 |
+
'๐บ๐ธ ๐น Onyx': 'am_onyx',
|
| 27 |
+
'๐บ๐ธ ๐น Santa': 'am_santa',
|
| 28 |
+
'๐บ๐ธ ๐น Adam': 'am_adam',
|
| 29 |
+
'๐ฌ๐ง ๐บ Emma': 'bf_emma',
|
| 30 |
+
'๐ฌ๐ง ๐บ Isabella': 'bf_isabella',
|
| 31 |
+
'๐ฌ๐ง ๐บ Alice': 'bf_alice',
|
| 32 |
+
'๐ฌ๐ง ๐บ Lily': 'bf_lily',
|
| 33 |
+
'๐ฌ๐ง ๐น George': 'bm_george',
|
| 34 |
+
'๐ฌ๐ง ๐น Fable': 'bm_fable',
|
| 35 |
+
'๐ฌ๐ง ๐น Lewis': 'bm_lewis',
|
| 36 |
+
'๐ฌ๐ง ๐น Daniel': 'bm_daniel',
|
| 37 |
+
}
|
| 38 |
|
| 39 |
model = KModel().to('cpu').eval()
|
| 40 |
pipeline = KPipeline(lang_code='a', model=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
pipelines = {lang_code: KPipeline(lang_code=lang_code, model=False) for lang_code in 'ab'}
|
| 43 |
+
pipelines['a'].g2p.lexicon.golds['kokoro'] = 'kหOkษษนO'
|
| 44 |
+
pipelines['b'].g2p.lexicon.golds['kokoro'] = 'kหQkษษนQ'
|
| 45 |
|
| 46 |
def generate_tts(text, voice='af_heart', speed=1):
|
| 47 |
+
pipeline = pipelines[voice[0]]
|
| 48 |
pack = pipeline.load_voice(voice)
|
| 49 |
first = True
|
| 50 |
for _, ps, _ in pipeline(text, voice, speed):
|