Merge pull request #102 from daily-co/examples-cleanup
examples cleanup
This commit is contained in:
@@ -6,6 +6,9 @@ import os
|
|||||||
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
||||||
from dailyai.transports.local_transport import LocalTransport
|
from dailyai.transports.local_transport import LocalTransport
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv(override=True)
|
||||||
|
|
||||||
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
||||||
logger = logging.getLogger("dailyai")
|
logger = logging.getLogger("dailyai")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
@@ -25,10 +28,7 @@ async def main():
|
|||||||
|
|
||||||
async def say_something():
|
async def say_something():
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
await tts.say(
|
await transport.say("Hello there.", tts)
|
||||||
"Hello there.",
|
|
||||||
transport.send_queue,
|
|
||||||
)
|
|
||||||
await transport.stop_when_done()
|
await transport.stop_when_done()
|
||||||
|
|
||||||
await asyncio.gather(transport.run(), say_something())
|
await asyncio.gather(transport.run(), say_something())
|
||||||
|
|||||||
@@ -5,26 +5,29 @@ import os
|
|||||||
|
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
|
||||||
from dailyai.pipeline.frames import TextFrame
|
from dailyai.pipeline.frames import TextFrame, EndFrame
|
||||||
|
from dailyai.pipeline.pipeline import Pipeline
|
||||||
from dailyai.services.fal_ai_services import FalImageGenService
|
from dailyai.services.fal_ai_services import FalImageGenService
|
||||||
from dailyai.transports.local_transport import LocalTransport
|
from dailyai.transports.local_transport import LocalTransport
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv(override=True)
|
||||||
|
|
||||||
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
||||||
logger = logging.getLogger("dailyai")
|
logger = logging.getLogger("dailyai")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
local_joined = False
|
|
||||||
participant_joined = False
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
meeting_duration_minutes = 2
|
meeting_duration_minutes = 2
|
||||||
|
|
||||||
tk_root = tk.Tk()
|
tk_root = tk.Tk()
|
||||||
tk_root.title("Calendar")
|
tk_root.title("dailyai")
|
||||||
|
|
||||||
transport = LocalTransport(
|
transport = LocalTransport(
|
||||||
tk_root=tk_root,
|
tk_root=tk_root,
|
||||||
mic_enabled=True,
|
mic_enabled=False,
|
||||||
camera_enabled=True,
|
camera_enabled=True,
|
||||||
camera_width=1024,
|
camera_width=1024,
|
||||||
camera_height=1024,
|
camera_height=1024,
|
||||||
@@ -32,15 +35,14 @@ async def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
imagegen = FalImageGenService(
|
imagegen = FalImageGenService(
|
||||||
image_size="1024x1024",
|
image_size="square_hd",
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
key_id=os.getenv("FAL_KEY_ID"),
|
key_id=os.getenv("FAL_KEY_ID"),
|
||||||
key_secret=os.getenv("FAL_KEY_SECRET"),
|
key_secret=os.getenv("FAL_KEY_SECRET"),
|
||||||
)
|
)
|
||||||
image_task = asyncio.create_task(
|
|
||||||
imagegen.run_to_queue(
|
pipeline = Pipeline([imagegen])
|
||||||
transport.send_queue, [
|
await pipeline.queue_frames([TextFrame("a cat in the style of picasso")])
|
||||||
TextFrame("a cat in the style of picasso")]))
|
|
||||||
|
|
||||||
async def run_tk():
|
async def run_tk():
|
||||||
while not transport._stop_threads.is_set():
|
while not transport._stop_threads.is_set():
|
||||||
@@ -48,7 +50,7 @@ async def main():
|
|||||||
tk_root.update_idletasks()
|
tk_root.update_idletasks()
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
|
|
||||||
await asyncio.gather(transport.run(), image_task, run_tk())
|
await asyncio.gather(transport.run(pipeline, override_pipeline_source_queue=False), run_tk())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ import logging
|
|||||||
|
|
||||||
from dailyai.transports.daily_transport import DailyTransport
|
from dailyai.transports.daily_transport import DailyTransport
|
||||||
from dailyai.services.whisper_ai_services import WhisperSTTService
|
from dailyai.services.whisper_ai_services import WhisperSTTService
|
||||||
|
from dailyai.pipeline.pipeline import Pipeline
|
||||||
|
|
||||||
from runner import configure
|
from runner import configure
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
load_dotenv(override=True)
|
|
||||||
|
|
||||||
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
||||||
logger = logging.getLogger("dailyai")
|
logger = logging.getLogger("dailyai")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
@@ -19,27 +17,26 @@ async def main(room_url: str):
|
|||||||
room_url,
|
room_url,
|
||||||
None,
|
None,
|
||||||
"Transcription bot",
|
"Transcription bot",
|
||||||
start_transcription=True,
|
start_transcription=False,
|
||||||
mic_enabled=False,
|
mic_enabled=False,
|
||||||
camera_enabled=False,
|
camera_enabled=False,
|
||||||
speaker_enabled=True,
|
speaker_enabled=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
stt = WhisperSTTService()
|
stt = WhisperSTTService()
|
||||||
|
|
||||||
transcription_output_queue = asyncio.Queue()
|
transcription_output_queue = asyncio.Queue()
|
||||||
|
|
||||||
|
pipeline = Pipeline([stt])
|
||||||
|
pipeline.set_sink(transcription_output_queue)
|
||||||
|
|
||||||
async def handle_transcription():
|
async def handle_transcription():
|
||||||
print("`````````TRANSCRIPTION`````````")
|
print("`````````TRANSCRIPTION`````````")
|
||||||
while True:
|
while True:
|
||||||
item = await transcription_output_queue.get()
|
item = await transcription_output_queue.get()
|
||||||
print(item.text)
|
print(item.text)
|
||||||
|
|
||||||
async def handle_speaker():
|
await asyncio.gather(transport.run(pipeline), handle_transcription())
|
||||||
await stt.run_to_queue(
|
|
||||||
transcription_output_queue, transport.get_receive_frames()
|
|
||||||
)
|
|
||||||
|
|
||||||
await asyncio.gather(transport.run(), handle_speaker(), handle_transcription())
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,32 +1,35 @@
|
|||||||
import argparse
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from dailyai.pipeline.frames import EndFrame, TranscriptionFrame
|
|
||||||
|
|
||||||
|
from dailyai.pipeline.frames import EndFrame, TranscriptionFrame
|
||||||
from dailyai.transports.local_transport import LocalTransport
|
from dailyai.transports.local_transport import LocalTransport
|
||||||
from dailyai.services.whisper_ai_services import WhisperSTTService
|
from dailyai.services.whisper_ai_services import WhisperSTTService
|
||||||
|
from dailyai.pipeline.pipeline import Pipeline
|
||||||
|
|
||||||
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
||||||
logger = logging.getLogger("dailyai")
|
logger = logging.getLogger("dailyai")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
async def main(room_url: str):
|
async def main():
|
||||||
global transport
|
|
||||||
global stt
|
|
||||||
|
|
||||||
meeting_duration_minutes = 1
|
meeting_duration_minutes = 1
|
||||||
|
|
||||||
transport = LocalTransport(
|
transport = LocalTransport(
|
||||||
mic_enabled=True,
|
mic_enabled=False,
|
||||||
camera_enabled=False,
|
camera_enabled=False,
|
||||||
speaker_enabled=True,
|
speaker_enabled=True,
|
||||||
duration_minutes=meeting_duration_minutes,
|
duration_minutes=meeting_duration_minutes,
|
||||||
start_transcription=True,
|
start_transcription=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
stt = WhisperSTTService()
|
stt = WhisperSTTService()
|
||||||
|
|
||||||
transcription_output_queue = asyncio.Queue()
|
transcription_output_queue = asyncio.Queue()
|
||||||
transport_done = asyncio.Event()
|
transport_done = asyncio.Event()
|
||||||
|
|
||||||
|
pipeline = Pipeline([stt])
|
||||||
|
pipeline.set_sink(transcription_output_queue)
|
||||||
|
|
||||||
async def handle_transcription():
|
async def handle_transcription():
|
||||||
print("`````````TRANSCRIPTION`````````")
|
print("`````````TRANSCRIPTION`````````")
|
||||||
while not transport_done.is_set():
|
while not transport_done.is_set():
|
||||||
@@ -38,29 +41,13 @@ async def main(room_url: str):
|
|||||||
break
|
break
|
||||||
print("handle_transcription done")
|
print("handle_transcription done")
|
||||||
|
|
||||||
async def handle_speaker():
|
|
||||||
await stt.run_to_queue(
|
|
||||||
transcription_output_queue, transport.get_receive_frames()
|
|
||||||
)
|
|
||||||
await transcription_output_queue.put(EndFrame())
|
|
||||||
print("handle speaker done.")
|
|
||||||
|
|
||||||
async def run_until_done():
|
async def run_until_done():
|
||||||
await transport.run()
|
await transport.run(pipeline)
|
||||||
transport_done.set()
|
transport_done.set()
|
||||||
print("run_until_done done")
|
print("run_until_done done")
|
||||||
|
|
||||||
await asyncio.gather(run_until_done(), handle_speaker(), handle_transcription())
|
await asyncio.gather(run_until_done(), handle_transcription())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description="Simple Daily Bot Sample")
|
asyncio.run(main())
|
||||||
parser.add_argument(
|
|
||||||
"-u",
|
|
||||||
"--url",
|
|
||||||
type=str,
|
|
||||||
required=True,
|
|
||||||
help="URL of the Daily room to join")
|
|
||||||
|
|
||||||
args, unknown = parser.parse_known_args()
|
|
||||||
asyncio.run(main(args.url))
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import argparse
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
@@ -11,12 +10,15 @@ from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
|||||||
from dailyai.services.fal_ai_services import FalImageGenService
|
from dailyai.services.fal_ai_services import FalImageGenService
|
||||||
from dailyai.transports.local_transport import LocalTransport
|
from dailyai.transports.local_transport import LocalTransport
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv(override=True)
|
||||||
|
|
||||||
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
|
||||||
logger = logging.getLogger("dailyai")
|
logger = logging.getLogger("dailyai")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
async def main(room_url):
|
async def main():
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
meeting_duration_minutes = 5
|
meeting_duration_minutes = 5
|
||||||
tk_root = tk.Tk()
|
tk_root = tk.Tk()
|
||||||
@@ -59,12 +61,8 @@ async def main(room_url):
|
|||||||
return all_audio
|
return all_audio
|
||||||
|
|
||||||
async def get_month_data(month):
|
async def get_month_data(month):
|
||||||
messages = [
|
messages = [{"role": "system", "content": f"Describe a nature photograph suitable for use in a calendar, for the month of {
|
||||||
{
|
month}. Include only the image description with no preamble. Limit the description to one sentence, please.", }]
|
||||||
"role": "system",
|
|
||||||
"content": f"Describe a nature photograph suitable for use in a calendar, for the month of {month}. Include only the image description with no preamble. Limit the description to one sentence, please.",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
image_description = await llm.run_llm(messages)
|
image_description = await llm.run_llm(messages)
|
||||||
if not image_description:
|
if not image_description:
|
||||||
@@ -133,14 +131,4 @@ async def main(room_url):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description="Simple Daily Bot Sample")
|
asyncio.run(main())
|
||||||
parser.add_argument(
|
|
||||||
"-u",
|
|
||||||
"--url",
|
|
||||||
type=str,
|
|
||||||
required=True,
|
|
||||||
help="URL of the Daily room to join")
|
|
||||||
|
|
||||||
args, unknown = parser.parse_known_args()
|
|
||||||
|
|
||||||
asyncio.run(main(args.url))
|
|
||||||
@@ -27,7 +27,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Source = "https://github.com/daily-co/daily-ai-sdk"
|
Source = "https://github.com/daily-co/dailyai"
|
||||||
Website = "https://daily.co"
|
Website = "https://daily.co"
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import io
|
|||||||
import os
|
import os
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from dailyai.services.ai_services import ImageGenService
|
|
||||||
|
|
||||||
|
|
||||||
from dailyai.services.ai_services import ImageGenService
|
from dailyai.services.ai_services import ImageGenService
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import signal
|
|||||||
import threading
|
import threading
|
||||||
import types
|
import types
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -120,8 +119,7 @@ class DailyTransport(ThreadedTransport, EventHandler):
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
def _webrtc_vad_analyze(self):
|
def _webrtc_vad_analyze(self):
|
||||||
buffer = self.read_audio_frames(
|
buffer = self.read_audio_frames(int(self._vad_samples))
|
||||||
int(self._vad_samples))
|
|
||||||
if len(buffer) > 0:
|
if len(buffer) > 0:
|
||||||
confidence = self.webrtc_vad.analyze_frames(buffer)
|
confidence = self.webrtc_vad.analyze_frames(buffer)
|
||||||
# yeses = int(confidence * 20.0)
|
# yeses = int(confidence * 20.0)
|
||||||
|
|||||||
@@ -48,13 +48,16 @@ class LocalTransport(ThreadedTransport):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def write_frame_to_mic(self, frame: bytes):
|
def write_frame_to_mic(self, frame: bytes):
|
||||||
self._audio_stream.write(frame)
|
if self._mic_enabled:
|
||||||
|
self._audio_stream.write(frame)
|
||||||
|
|
||||||
def read_frames(self, desired_frame_count):
|
def read_frames(self, desired_frame_count):
|
||||||
bytes = self._speaker_stream.read(
|
bytes = b""
|
||||||
desired_frame_count,
|
if self._speaker_enabled:
|
||||||
exception_on_overflow=False,
|
bytes = self._speaker_stream.read(
|
||||||
)
|
desired_frame_count,
|
||||||
|
exception_on_overflow=False,
|
||||||
|
)
|
||||||
return bytes
|
return bytes
|
||||||
|
|
||||||
def _prerun(self):
|
def _prerun(self):
|
||||||
|
|||||||
@@ -84,12 +84,13 @@ class ThreadedTransport(AbstractTransport):
|
|||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
if self._has_webrtc_vad:
|
if self._has_webrtc_vad:
|
||||||
self._logger.debug(f"Couldn't load torch; using webrtc VAD")
|
self._logger.debug(
|
||||||
|
f"Couldn't load torch; using webrtc VAD")
|
||||||
self._vad_samples = int(self._speaker_sample_rate / 100.0)
|
self._vad_samples = int(self._speaker_sample_rate / 100.0)
|
||||||
else:
|
else:
|
||||||
self._logger.error(f"Exception: {e}")
|
self._logger.error(f"Exception: {e}")
|
||||||
self._logger.error(
|
self._logger.error(
|
||||||
"In order to use VAD, you'll need to install the `torch` and `torchaudio` modules.")
|
"In order to use Silero VAD, you'll need to `pip install dailyai[silero].")
|
||||||
raise Exception(f"Missing module(s): {e}")
|
raise Exception(f"Missing module(s): {e}")
|
||||||
|
|
||||||
vad_frame_s = self._vad_samples / self._speaker_sample_rate
|
vad_frame_s = self._vad_samples / self._speaker_sample_rate
|
||||||
@@ -184,7 +185,6 @@ class ThreadedTransport(AbstractTransport):
|
|||||||
pipeline.set_sink(self.send_queue)
|
pipeline.set_sink(self.send_queue)
|
||||||
source_queue = asyncio.Queue()
|
source_queue = asyncio.Queue()
|
||||||
pipeline.set_source(source_queue)
|
pipeline.set_source(source_queue)
|
||||||
pipeline.set_sink(self.send_queue)
|
|
||||||
pipeline_task = asyncio.create_task(pipeline.run_pipeline())
|
pipeline_task = asyncio.create_task(pipeline.run_pipeline())
|
||||||
|
|
||||||
async def yield_frame(frame: Frame) -> AsyncGenerator[Frame, None]:
|
async def yield_frame(frame: Frame) -> AsyncGenerator[Frame, None]:
|
||||||
|
|||||||
Reference in New Issue
Block a user