Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: fix whisper examples #104

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions examples/foundational/13-whisper-transcription.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import asyncio
import logging

from dailyai.pipeline.frames import EndFrame, TranscriptionFrame
from dailyai.transports.daily_transport import DailyTransport
from dailyai.services.whisper_ai_services import WhisperSTTService
from dailyai.pipeline.pipeline import Pipeline

from runner import configure

from dotenv import load_dotenv
load_dotenv(override=True)

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)
Expand All @@ -26,17 +30,27 @@ async def main(room_url: str):
stt = WhisperSTTService()

transcription_output_queue = asyncio.Queue()
transport_done = asyncio.Event()

pipeline = Pipeline([stt])
pipeline.set_sink(transcription_output_queue)
pipeline = Pipeline([stt], source=transport.receive_queue, sink=transcription_output_queue)

async def handle_transcription():
print("`````````TRANSCRIPTION`````````")
while True:
while not transport_done.is_set():
item = await transcription_output_queue.get()
print(item.text)

await asyncio.gather(transport.run(pipeline), handle_transcription())
print("got item from queue", item)
if isinstance(item, TranscriptionFrame):
print(item.text)
elif isinstance(item, EndFrame):
break
print("handle_transcription done")

async def run_until_done():
await transport.run()
transport_done.set()
print("run_until_done done")

await asyncio.gather(run_until_done(), pipeline.run_pipeline(), handle_transcription())


if __name__ == "__main__":
Expand Down
10 changes: 4 additions & 6 deletions examples/foundational/13a-whisper-local.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ async def main():
meeting_duration_minutes = 1

transport = LocalTransport(
mic_enabled=False,
mic_enabled=True,
camera_enabled=False,
speaker_enabled=True,
duration_minutes=meeting_duration_minutes,
start_transcription=False,
)

stt = WhisperSTTService()

transcription_output_queue = asyncio.Queue()
transport_done = asyncio.Event()

pipeline = Pipeline([stt])
pipeline.set_sink(transcription_output_queue)
pipeline = Pipeline([stt], source=transport.receive_queue, sink=transcription_output_queue)

async def handle_transcription():
print("`````````TRANSCRIPTION`````````")
Expand All @@ -42,11 +40,11 @@ async def handle_transcription():
print("handle_transcription done")

async def run_until_done():
await transport.run(pipeline)
await transport.run()
transport_done.set()
print("run_until_done done")

await asyncio.gather(run_until_done(), handle_transcription())
await asyncio.gather(run_until_done(), pipeline.run_pipeline(), handle_transcription())


if __name__ == "__main__":
Expand Down
Loading