elevenlabs test in 02-
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import aiohttp
|
||||
import os
|
||||
import requests
|
||||
import time
|
||||
|
||||
from typing import Generator
|
||||
from typing import AsyncGenerator
|
||||
|
||||
from ..services.ai_services import TTSService
|
||||
from dailyai.services.ai_services import TTSService
|
||||
|
||||
|
||||
class ElevenLabsTTSService(TTSService):
|
||||
@@ -14,25 +15,22 @@ class ElevenLabsTTSService(TTSService):
|
||||
self.api_key = os.getenv("ELEVENLABS_API_KEY")
|
||||
self.voice_id = os.getenv("ELEVENLABS_VOICE_ID")
|
||||
|
||||
def run_tts(self, sentence) -> Generator[bytes, None, None]:
|
||||
url = f"https://api.elevenlabs.io/v1/text-to-speech/{self.voice_id}/stream"
|
||||
payload = {"text": sentence, "model_id": "eleven_turbo_v2"}
|
||||
querystring = {"output_format": "pcm_16000", "optimize_streaming_latency": 2}
|
||||
headers = {
|
||||
"xi-api-key": self.api_key,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
async def run_tts(self, sentence) -> AsyncGenerator[bytes, None]:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
url = f"https://api.elevenlabs.io/v1/text-to-speech/{self.voice_id}/stream"
|
||||
payload = {"text": sentence, "model_id": "eleven_turbo_v2"}
|
||||
querystring = {"output_format": "pcm_16000", "optimize_streaming_latency": 2}
|
||||
headers = {
|
||||
"xi-api-key": self.api_key,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
async with session.post(url, json=payload, headers=headers, params=querystring) as r:
|
||||
if r.status != 200:
|
||||
self.logger.error(
|
||||
f"audio fetch status code: {r.status}, error: {r.text}"
|
||||
)
|
||||
return
|
||||
|
||||
r = requests.request(
|
||||
"POST", url, json=payload, headers=headers, params=querystring, stream=True
|
||||
)
|
||||
|
||||
if r.status_code != 200:
|
||||
self.logger.error(
|
||||
f"audio fetch status code: {r.status_code}, error: {r.text}"
|
||||
)
|
||||
return
|
||||
|
||||
for chunk in r.iter_content(chunk_size=3200):
|
||||
if chunk:
|
||||
yield chunk
|
||||
async for chunk in r.content:
|
||||
if chunk:
|
||||
yield chunk
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
def hello(p):
|
||||
def decorator(f):
|
||||
print("running f", p)
|
||||
return f
|
||||
|
||||
return decorator
|
||||
|
||||
@hello("world")
|
||||
def foo():
|
||||
print("hi")
|
||||
@@ -4,7 +4,8 @@ from typing import AsyncGenerator
|
||||
|
||||
from dailyai.output_queue import OutputQueueFrame, FrameType
|
||||
from dailyai.services.daily_transport_service import DailyTransportService
|
||||
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
|
||||
from dailyai.services.azure_ai_services import AzureLLMService
|
||||
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
||||
|
||||
local_joined = False
|
||||
participant_joined = False
|
||||
@@ -19,7 +20,7 @@ async def main(room_url):
|
||||
)
|
||||
transport.mic_enabled = True
|
||||
|
||||
tts = AzureTTSService()
|
||||
tts = ElevenLabsTTSService()
|
||||
llm = AzureLLMService()
|
||||
|
||||
messages = [{
|
||||
|
||||
Reference in New Issue
Block a user