-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtranscriber.py
33 lines (26 loc) · 1.03 KB
/
transcriber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Transcribes user speech to text, and saves it to a file
from pathlib import Path
from dotenv import load_dotenv
from livekit.agents import JobContext, WorkerOptions, cli
from livekit.agents.voice import Agent, AgentSession
from livekit.plugins import deepgram
import datetime
load_dotenv(dotenv_path=Path(__file__).parent.parent / '.env')
async def entrypoint(ctx: JobContext):
await ctx.connect()
session = AgentSession()
@session.on("user_input_transcribed")
def on_transcript(transcript):
if transcript.is_final:
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open("user_speech_log.txt", "a") as f:
f.write(f"[{timestamp}] {transcript.transcript}\n")
await session.start(
agent=Agent(
instructions="You are a helpful assistant that transcribes user speech to text.",
stt=deepgram.STT()
),
room=ctx.room
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))