Fix circular dependency in voice streamed example with cleaner import pattern
This commit is contained in:
parent
9473c788ba
commit
fdf340495b
1 changed files with 12 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
|
|
@ -13,13 +14,18 @@ from typing_extensions import override
|
||||||
|
|
||||||
from agents.voice import StreamedAudioInput, VoicePipeline
|
from agents.voice import StreamedAudioInput, VoicePipeline
|
||||||
|
|
||||||
# Use absolute or relative import based on context
|
# Import MyWorkflow class - handle both module and package use cases
|
||||||
if __name__ == "__main__":
|
if TYPE_CHECKING:
|
||||||
# When running as script, use absolute import
|
# For type checking, use the relative import
|
||||||
from my_workflow import MyWorkflow # type: ignore
|
|
||||||
else:
|
|
||||||
# When imported as module, use relative import
|
|
||||||
from .my_workflow import MyWorkflow
|
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
|
CHUNK_LENGTH_S = 0.05 # 100ms
|
||||||
SAMPLE_RATE = 24000
|
SAMPLE_RATE = 24000
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue