a little cleanup, uglier-than-I'd-like 01-say-one-thing sample added
This commit is contained in:
@@ -4,8 +4,6 @@ from abc import abstractmethod
|
||||
from collections.abc import AsyncGenerator
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Generator
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class AIService:
|
||||
@@ -20,7 +18,7 @@ class LLMService(AIService):
|
||||
@abstractmethod
|
||||
async def run_llm_async(
|
||||
self, messages
|
||||
) -> AsyncGenerator[str, None, None]:
|
||||
) -> AsyncGenerator[str, None]:
|
||||
pass
|
||||
|
||||
# Generate a responses to a prompt. Returns the response
|
||||
@@ -39,14 +37,14 @@ class TTSService(AIService):
|
||||
# Converts the sentence to audio. Yields a list of audio frames that can
|
||||
# be sent to the microphone device
|
||||
@abstractmethod
|
||||
async def run_tts(self, sentence) -> AsyncGenerator[bytes, None, None]:
|
||||
async def run_tts(self, sentence) -> AsyncGenerator[bytes, None]:
|
||||
pass
|
||||
|
||||
|
||||
class ImageGenService(AIService):
|
||||
# Renders the image. Returns an Image object.
|
||||
@abstractmethod
|
||||
async def run_image_gen(self, sentence) -> tuple[str, Image.Image]:
|
||||
async def run_image_gen(self, sentence) -> tuple[str, bytes]:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class AzureTTSService(TTSService):
|
||||
self.speech_config = SpeechConfig(subscription=speech_key, region=speech_region)
|
||||
self.speech_synthesizer = SpeechSynthesizer(speech_config=self.speech_config, audio_config=None)
|
||||
|
||||
async def run_tts(self, sentence) -> AsyncGenerator[bytes, None, None]:
|
||||
async def run_tts(self, sentence) -> AsyncGenerator[bytes, None]:
|
||||
self.logger.info("Running azure tts")
|
||||
ssml = "<speak version='1.0' xml:lang='en-US' xmlns='http://www.w3.org/2001/10/synthesis' " \
|
||||
"xmlns:mstts='http://www.w3.org/2001/mstts'>" \
|
||||
@@ -99,7 +99,7 @@ class AzureImageGenServiceREST(ImageGenService):
|
||||
self.api_version = api_version or "2023-06-01-preview"
|
||||
self.model = model or os.getenv("AZURE_DALLE_DEPLOYMENT_ID")
|
||||
|
||||
async def run_image_gen(self, sentence, size) -> tuple[str, Image.Image]:
|
||||
async def run_image_gen(self, sentence, size) -> tuple[str, bytes]:
|
||||
# TODO hoist the session to app-level
|
||||
async with aiohttp.ClientSession() as session:
|
||||
url = f"{self.azure_endpoint}openai/images/generations:submit?api-version={self.api_version}"
|
||||
@@ -115,6 +115,7 @@ class AzureImageGenServiceREST(ImageGenService):
|
||||
|
||||
status = ""
|
||||
attempts_left = 120
|
||||
json_response = None
|
||||
while status != "succeeded":
|
||||
attempts_left -= 1
|
||||
if attempts_left == 0:
|
||||
@@ -125,7 +126,9 @@ class AzureImageGenServiceREST(ImageGenService):
|
||||
json_response = await response.json()
|
||||
status = json_response["status"]
|
||||
|
||||
image_url = json_response["result"]["data"][0]["url"]
|
||||
image_url = json_response["result"]["data"][0]["url"] if json_response else None
|
||||
if not image_url:
|
||||
raise Exception("Image generation failed")
|
||||
|
||||
# Load the image from the url
|
||||
async with session.get(image_url) as response:
|
||||
|
||||
@@ -23,14 +23,14 @@ class DailyTransportService(EventHandler):
|
||||
def __init__(
|
||||
self,
|
||||
room_url: str,
|
||||
token: str,
|
||||
token: str | None,
|
||||
bot_name: str,
|
||||
duration: float = 10,
|
||||
):
|
||||
super().__init__()
|
||||
self.bot_name: str = bot_name
|
||||
self.room_url: str = room_url
|
||||
self.token: str = token
|
||||
self.token: str | None = token
|
||||
self.duration: float = duration
|
||||
self.expiration = time.time() + duration * 60
|
||||
|
||||
@@ -38,6 +38,9 @@ class DailyTransportService(EventHandler):
|
||||
self.is_interrupted = Event()
|
||||
self.stop_threads = Event()
|
||||
self.story_started = False
|
||||
self.mic_enabled = False
|
||||
self.mic_sample_rate = 16000
|
||||
self.camera_enabled = False
|
||||
|
||||
self.logger: logging.Logger = logging.getLogger("dailyai")
|
||||
|
||||
@@ -129,6 +132,7 @@ class DailyTransportService(EventHandler):
|
||||
self.configure_daily()
|
||||
self.running_thread = Thread(target=self.run_daily, daemon=True)
|
||||
self.running_thread.start()
|
||||
self.running_thread.join()
|
||||
|
||||
def run_daily(self):
|
||||
# TODO: this loop could, I think, be replaced with a timer and an event
|
||||
|
||||
Reference in New Issue
Block a user