Spaces:
Runtime error
Runtime error
basic get speech working without streaming
Browse files- chat_service.py +3 -0
- debug.py +4 -1
- environment.yml +1 -0
- requirements.txt +2 -1
- speech_service.py +32 -0
chat_service.py
CHANGED
|
@@ -10,6 +10,9 @@ class ChatService:
|
|
| 10 |
# def __init__(self, api="huggingface", model_id = "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"):
|
| 11 |
self._api = api
|
| 12 |
self._device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
if self._api=="openai":
|
| 15 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
| 10 |
# def __init__(self, api="huggingface", model_id = "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"):
|
| 11 |
self._api = api
|
| 12 |
self._device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 13 |
+
self._system_prompt = None
|
| 14 |
+
self._user_name = None
|
| 15 |
+
self._agent_name = None
|
| 16 |
|
| 17 |
if self._api=="openai":
|
| 18 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
debug.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from clip_transform import CLIPTransform
|
| 2 |
from chat_service import ChatService
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
-
|
| 5 |
|
| 6 |
load_dotenv()
|
| 7 |
|
|
@@ -11,6 +11,7 @@ print ("CLIP success")
|
|
| 11 |
|
| 12 |
print ("Initializing Chat")
|
| 13 |
chat_service = ChatService()
|
|
|
|
| 14 |
prompts = [
|
| 15 |
"hello, how are you today?",
|
| 16 |
"tell me about your showdow self?",
|
|
@@ -21,5 +22,7 @@ for prompt in prompts:
|
|
| 21 |
print (f'prompt: "{prompt}"')
|
| 22 |
response = chat_service.chat(prompt)
|
| 23 |
print (f'response: "{response}"')
|
|
|
|
|
|
|
| 24 |
|
| 25 |
print ("Chat success")
|
|
|
|
| 1 |
from clip_transform import CLIPTransform
|
| 2 |
from chat_service import ChatService
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
+
from speech_service import SpeechService
|
| 5 |
|
| 6 |
load_dotenv()
|
| 7 |
|
|
|
|
| 11 |
|
| 12 |
print ("Initializing Chat")
|
| 13 |
chat_service = ChatService()
|
| 14 |
+
speech_service = SpeechService()
|
| 15 |
prompts = [
|
| 16 |
"hello, how are you today?",
|
| 17 |
"tell me about your showdow self?",
|
|
|
|
| 22 |
print (f'prompt: "{prompt}"')
|
| 23 |
response = chat_service.chat(prompt)
|
| 24 |
print (f'response: "{response}"')
|
| 25 |
+
speech_service.speak(response)
|
| 26 |
+
|
| 27 |
|
| 28 |
print ("Chat success")
|
environment.yml
CHANGED
|
@@ -20,3 +20,4 @@ dependencies:
|
|
| 20 |
- vosk
|
| 21 |
- transformers
|
| 22 |
- openai
|
|
|
|
|
|
| 20 |
- vosk
|
| 21 |
- transformers
|
| 22 |
- openai
|
| 23 |
+
- elevenlabs
|
requirements.txt
CHANGED
|
@@ -15,4 +15,5 @@ torch
|
|
| 15 |
numpy
|
| 16 |
open_clip_torch
|
| 17 |
transformers
|
| 18 |
-
openai
|
|
|
|
|
|
| 15 |
numpy
|
| 16 |
open_clip_torch
|
| 17 |
transformers
|
| 18 |
+
openai
|
| 19 |
+
elevenlabs
|
speech_service.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from elevenlabs import generate, play
|
| 3 |
+
from elevenlabs import set_api_key
|
| 4 |
+
from elevenlabs import generate, stream
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SpeechService:
|
| 8 |
+
def __init__(self):
|
| 9 |
+
account_sid = os.environ["ELEVENLABS_API_KEY"]
|
| 10 |
+
set_api_key(account_sid)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def speak(self, prompt):
|
| 14 |
+
# audio = generate(
|
| 15 |
+
# text=prompt,
|
| 16 |
+
# voice="Bella",
|
| 17 |
+
# model="eleven_monolingual_v1"
|
| 18 |
+
# )
|
| 19 |
+
# play(audio)
|
| 20 |
+
audio_stream = generate(
|
| 21 |
+
text=prompt,
|
| 22 |
+
stream=True
|
| 23 |
+
)
|
| 24 |
+
# stream(audio_stream)
|
| 25 |
+
audio = b""
|
| 26 |
+
for chunk in audio_stream:
|
| 27 |
+
if chunk is not None:
|
| 28 |
+
audio += chunk
|
| 29 |
+
# play(chunk)
|
| 30 |
+
play(audio)
|
| 31 |
+
return
|
| 32 |
+
|