Skip to main content سوق المهارات اكتشف واستكشف مهارات الذكاء الاصطناعي التي بناها المجتمع.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
نسخ Promptعرض تفاصيل Prompt يتجاوز الأمر المباشر Prompt المخصّص للمراجعة. افحص المصدر قبل تشغيله.
npx skills add https://github.com/BEKO2210/Firstbrain --skill azure-ai-voicelive-pyيبقى الأمر في سطر واحد. مرّر أفقيًا لمراجعته كاملًا قبل النسخ.
تفضّل نسخة محلية؟ نزّل الملفات المتاحة حاليًا لدى SkillsMP.
تحميل Zip جاري التحميل... المهن ذات الصلة SOC
استنادا إلى تصنيف SOC المهني
name azure-ai-voicelive-py description Build real-time voice AI applications with bidirectional WebSocket communication. type skill created 2026-02-27T00:00:00.000Z domain cloud-infrastructure category azure risk unknown source community tags ["skill","cloud-infrastructure","azure","voicelive"]
Azure AI Voice Live SDK
Build real-time voice AI applications with bidirectional WebSocket communication.
Installation
pip install azure-ai-voicelive aiohttp azure-identity
Environment Variables
AZURE_COGNITIVE_SERVICES_ENDPOINT=https://<region>.api.cognitive.microsoft.com
AZURE_COGNITIVE_SERVICES_KEY=<api-key>
Authentication
DefaultAzureCredential (preferred) :
from azure.ai.voicelive.aio import connect
from azure.identity.aio import DefaultAzureCredential
async with connect(
endpoint=os.environ["AZURE_COGNITIVE_SERVICES_ENDPOINT" ],
credential=DefaultAzureCredential(),
model="gpt-4o-realtime-preview" ,
credential_scopes=["https://cognitiveservices.azure.com/.default" ]
) as conn:
...
API Key :
from azure.ai.voicelive.aio import connect
from azure.core.credentials import AzureKeyCredential
async with connect(
endpoint=os.environ["AZURE_COGNITIVE_SERVICES_ENDPOINT" ],
credential=AzureKeyCredential(os.environ["AZURE_COGNITIVE_SERVICES_KEY" ]),
model="gpt-4o-realtime-preview"
) as conn:
...
Quick Start
import asyncio
import os
from azure.ai.voicelive.aio import connect
from azure.identity.aio import DefaultAzureCredential
async def main ():
connect(
endpoint=os.environ[ ],
credential=DefaultAzureCredential(),
model= ,
credential_scopes=[ ]
) conn:
conn.session.update(session={
: ,
: [ , ],
:
})
event conn:
( )
event. == :
( )
event. == :
asyncio.run(main())
async
with
"AZURE_COGNITIVE_SERVICES_ENDPOINT"
"gpt-4o-realtime-preview"
"https://cognitiveservices.azure.com/.default"
as
await
"instructions"
"You are a helpful assistant."
"modalities"
"text"
"audio"
"voice"
"alloy"
async
for
in
print
f"Event: {event.type } "
if
type
"response.audio_transcript.done"
print
f"Transcript: {event.transcript} "
elif
type
"response.done"
break
Core Architecture
Connection Resources The VoiceLiveConnection exposes these resources:
Resource Purpose Key Methods conn.sessionSession configuration update(session=...)conn.responseModel responses create(), cancel()conn.input_audio_bufferAudio input append(), commit(), clear()conn.output_audio_bufferAudio output clear()conn.conversationConversation state item.create(), item.delete(), item.truncate()conn.transcription_sessionTranscription config update(session=...)
Session Configuration from azure.ai.voicelive.models import RequestSession, FunctionTool
await conn.session.update(session=RequestSession(
instructions="You are a helpful voice assistant." ,
modalities=["text" , "audio" ],
voice="alloy" ,
input_audio_format="pcm16" ,
output_audio_format="pcm16" ,
turn_detection={
"type" : "server_vad" ,
"threshold" : 0.5 ,
"prefix_padding_ms" : 300 ,
"silence_duration_ms" : 500
},
tools=[
FunctionTool(
type ="function" ,
name="get_weather" ,
description="Get current weather" ,
parameters={
"type" : "object" ,
"properties" : {
"location" : {"type" : "string" }
},
"required" : ["location" ]
}
)
]
))
Audio Streaming
Send Audio (Base64 PCM16) import base64
audio_chunk = await read_audio_from_microphone()
b64_audio = base64.b64encode(audio_chunk).decode()
await conn.input_audio_buffer.append(audio=b64_audio)
Receive Audio async for event in conn:
if event.type == "response.audio.delta" :
audio_bytes = base64.b64decode(event.delta)
await play_audio(audio_bytes)
elif event.type == "response.audio.done" :
print ("Audio complete" )
Event Handling async for event in conn:
match event.type :
case "session.created" :
print (f"Session: {event.session} " )
case "session.updated" :
print ("Session updated" )
case "input_audio_buffer.speech_started" :
print (f"Speech started at {event.audio_start_ms} ms" )
case "input_audio_buffer.speech_stopped" :
print (f"Speech stopped at {event.audio_end_ms} ms" )
case "conversation.item.input_audio_transcription.completed" :
print (f"User said: {event.transcript} " )
case "conversation.item.input_audio_transcription.delta" :
print (f"Partial: {event.delta} " )
case "response.created" :
print (f"Response started: {event.response.id } " )
case "response.audio_transcript.delta" :
print (event.delta, end="" , flush=True )
case "response.audio.delta" :
audio = base64.b64decode(event.delta)
case "response.done" :
print (f"Response complete: {event.response.status} " )
case "response.function_call_arguments.done" :
result = handle_function(event.name, event.arguments)
await conn.conversation.item.create(item={
"type" : "function_call_output" ,
"call_id" : event.call_id,
"output" : json.dumps(result)
})
await conn.response.create()
case "error" :
print (f"Error: {event.error.message} " )
Common Patterns
Manual Turn Mode (No VAD) await conn.session.update(session={"turn_detection" : None })
await conn.input_audio_buffer.append(audio=b64_audio)
await conn.input_audio_buffer.commit()
await conn.response.create()
Interrupt Handling async for event in conn:
if event.type == "input_audio_buffer.speech_started" :
await conn.response.cancel()
await conn.output_audio_buffer.clear()
Conversation History
await conn.conversation.item.create(item={
"type" : "message" ,
"role" : "system" ,
"content" : [{"type" : "input_text" , "text" : "Be concise." }]
})
await conn.conversation.item.create(item={
"type" : "message" ,
"role" : "user" ,
"content" : [{"type" : "input_text" , "text" : "Hello!" }]
})
await conn.response.create()
Voice Options Voice Description alloyNeutral, balanced echoWarm, conversational shimmerClear, professional sageCalm, authoritative coralFriendly, upbeat ashDeep, measured balladExpressive verseStorytelling
Azure voices: Use AzureStandardVoice, AzureCustomVoice, or AzurePersonalVoice models.
Audio Formats Format Sample Rate Use Case pcm1624kHz Default, high quality pcm16-8000hz8kHz Telephony pcm16-16000hz16kHz Voice assistants g711_ulaw8kHz Telephony (US) g711_alaw8kHz Telephony (EU)
Turn Detection Options
{"type" : "server_vad" , "threshold" : 0.5 , "silence_duration_ms" : 500 }
{"type" : "azure_semantic_vad" }
{"type" : "azure_semantic_vad_en" }
{"type" : "azure_semantic_vad_multilingual" }
Error Handling from azure.ai.voicelive.aio import ConnectionError, ConnectionClosed
try :
async with connect(...) as conn:
async for event in conn:
if event.type == "error" :
print (f"API Error: {event.error.code} - {event.error.message} " )
except ConnectionClosed as e:
print (f"Connection closed: {e.code} - {e.reason} " )
except ConnectionError as e:
print (f"Connection error: {e} " )
References
Detailed API Reference : See references/api-reference.md
Complete Examples : See references/examples.md
All Models & Types : See references/models.md
When to Use This skill is applicable to execute the workflow or actions described in the overview.
Connections
Domain: [[Cloud & Infrastruktur]]
Kategorie: [[Microsoft Azure]]
Navigation: [[Skills Uebersicht]], [[Home]]