Skip to content

Commit 45cfdcd

Browse files
committed
simplify sdk scenario instructions
1 parent 8b5b3a3 commit 45cfdcd

File tree

1 file changed

+71
-9
lines changed

1 file changed

+71
-9
lines changed

articles/ai-services/speech-service/how-to-bring-your-own-model.md

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,77 @@ Get the `<your-model-deployment>` value from the AI Foundry portal. It correspon
6767

6868
#### [Python SDK](#tab/sdk)
6969

70-
When using the Voice live Python SDK, configure the query parameter:
70+
Use the [Python SDK quickstart code](/azure/ai-services/speech-service/voice-live-quickstart?tabs=windows%2Ckeyless&pivots=programming-language-python) to start a voice conversation, and make the following changes to enable BYOM:
7171

72-
```json
73-
{
74-
"profile": "<your-byom-mode>"
75-
}
76-
```
72+
1. In the `parse_arguments()` function, add a new argument for the BYOM profile type:
73+
74+
```python
75+
parser.add_argument(
76+
"--byom",
77+
help="BYOM (Bring Your Own Model) profile type",
78+
type=str,
79+
choices=["byom-azure-openai-realtime", "byom-azure-openai-chat-completion"],
80+
default=os.environ.get("VOICELIVE_BYOM_MODE", "byom-azure-openai-chat-completion"),
81+
82+
)
83+
```
84+
85+
1. In the `BasicVoiceAssistant` class, add the byom field:
86+
87+
```python
88+
class BasicVoiceAssistant:
89+
"""Basic voice assistant implementing the VoiceLive SDK patterns."""
90+
91+
def __init__(
92+
self,
93+
endpoint: str,
94+
credential: Union[AzureKeyCredential, TokenCredential],
95+
model: str,
96+
voice: str,
97+
instructions: str,
98+
byom: Literal["byom-azure-openai-realtime", "byom-azure-openai-chat-completion"] | None = None
99+
):
100+
101+
self.endpoint = endpoint
102+
self.credential = credential
103+
self.model = model
104+
self.voice = voice
105+
self.instructions = instructions
106+
self.connection: Optional["VoiceLiveConnection"] = None
107+
self.audio_processor: Optional[AudioProcessor] = None
108+
self.session_ready = False
109+
self.conversation_started = False
110+
self.byom = byom
77111

78-
For a complete implementation example, refer to the sample code below. Get the model value from the AI Foundry portal. It corresponds to the name you gave the model at deployment time.
112+
async def start(self):
113+
"""Start the voice assistant session."""
114+
try:
115+
logger.info(f"Connecting to VoiceLive API with model {self.model}")
79116

117+
# Connect to VoiceLive WebSocket API
118+
async with connect(
119+
endpoint=self.endpoint,
120+
credential=self.credential,
121+
model=self.model,
122+
connection_options={
123+
"max_msg_size": 10 * 1024 * 1024,
124+
"heartbeat": 20,
125+
"timeout": 20,
126+
},
127+
query={
128+
"profile": self.byom
129+
} if self.byom else None
130+
) as connection:
131+
...
132+
```
133+
1. When you run the code, specify the `--byom` argument along with the `--model` argument to indicate the BYOM profile and model deployment you want to use. For example:
134+
135+
```shell
136+
python voice-live-quickstart.py --byom "byom-azure-openai-chat-completion" --model "gpt-4o"
137+
```
138+
139+
---
140+
<!--
80141
```python
81142
import os
82143
import sys
@@ -607,7 +668,8 @@ def parse_arguments():
607668
help="BYOM (Bring Your Own Model) profile type",
608669
type=str,
609670
choices=["byom-azure-openai-realtime", "byom-azure-openai-chat-completion"],
610-
default=None
671+
default=os.environ.get("VOICELIVE_BYOM_MODE", "byom-azure-openai-chat-completion"),
672+
611673
)
612674

613675
parser.add_argument("--verbose", help="Enable verbose logging", action="store_true")
@@ -726,4 +788,4 @@ if __name__ == "__main__":
726788
# Run the assistant
727789
asyncio.run(main())
728790
```
729-
791+
-->

0 commit comments

Comments
 (0)