Fix circular dependency in voice streamed example with cleaner import pattern

This commit is contained in:
Aviral Garg 2025-03-21 16:26:19 -07:00
parent 9473c788ba
commit fdf340495b

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import asyncio
from typing import TYPE_CHECKING
import numpy as np
import sounddevice as sd
@ -13,13 +14,18 @@ from typing_extensions import override
from agents.voice import StreamedAudioInput, VoicePipeline
# Use absolute or relative import based on context
if __name__ == "__main__":
# When running as script, use absolute import
from my_workflow import MyWorkflow # type: ignore
else:
# When imported as module, use relative import
# Import MyWorkflow class - handle both module and package use cases
if TYPE_CHECKING:
# For type checking, use the relative import
from .my_workflow import MyWorkflow
else:
# At runtime, try both import styles
try:
# Try relative import first (when used as a package)
from .my_workflow import MyWorkflow
except ImportError:
# Fall back to direct import (when run as a script)
from my_workflow import MyWorkflow
CHUNK_LENGTH_S = 0.05 # 100ms
SAMPLE_RATE = 24000