Skip to content

Commit fdf3404

Browse files
committedMar 21, 2025·
Fix circular dependency in voice streamed example with cleaner import pattern
1 parent 9473c78 commit fdf3404

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
 

‎examples/voice/streamed/main.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
from typing import TYPE_CHECKING
45

56
import numpy as np
67
import sounddevice as sd
@@ -13,13 +14,18 @@
1314

1415
from agents.voice import StreamedAudioInput, VoicePipeline
1516

16-
# Use absolute or relative import based on context
17-
if __name__ == "__main__":
18-
# When running as script, use absolute import
19-
from my_workflow import MyWorkflow # type: ignore
20-
else:
21-
# When imported as module, use relative import
17+
# Import MyWorkflow class - handle both module and package use cases
18+
if TYPE_CHECKING:
19+
# For type checking, use the relative import
2220
from .my_workflow import MyWorkflow
21+
else:
22+
# At runtime, try both import styles
23+
try:
24+
# Try relative import first (when used as a package)
25+
from .my_workflow import MyWorkflow
26+
except ImportError:
27+
# Fall back to direct import (when run as a script)
28+
from my_workflow import MyWorkflow
2329

2430
CHUNK_LENGTH_S = 0.05 # 100ms
2531
SAMPLE_RATE = 24000

0 commit comments

Comments
 (0)
Please sign in to comment.