代码拉取完成,页面将自动刷新
基于WebRTC的OpenAI实时音频流通信Python库,支持与OpenAI Realtime API进行实时音频交互。
sounddevice>=0.4.6
numpy>=1.24.0
websockets>=11.0.3
openai>=1.3.0
aiohttp>=3.8.5
pyaudio>=0.2.13
python-dotenv>=1.0.0
aiortc>=1.6.0
scipy>=1.12.0
git clone https://github.com/yourusername/openai-realtime-webrtc-python.git
cd openai-realtime-webrtc-python
python -m venv venv
source venv/bin/activate # Linux/macOS
pip install -r requirements.txt
pip install -e .
.env
文件并添加您的OpenAI API密钥:OPENAI_API_KEY=your-api-key-here
import asyncio
from openai_realtime_webrtc import OpenAIWebRTCClient
async def main():
# 创建客户端实例
client = OpenAIWebRTCClient(
api_key="your-api-key",
model="gpt-4o-realtime-preview-2024-12-17"
)
# 定义转录回调
def on_transcription(text: str):
print(f"转录文本: {text}")
client.on_transcription = on_transcription
try:
# 开始流式传输
await client.start_streaming()
# 保持连接
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
# 停止流式传输
await client.stop_streaming()
if __name__ == "__main__":
asyncio.run(main())
python examples/basic_streaming.py
欢迎提交 Pull Requests 和 Issues!
MIT License
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。