1 Star 0 Fork 0

建站_软件开发_手机APP/openai-realtime-webrtc-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

openai-realtime-webrtc-python

基于WebRTC的OpenAI实时音频流通信Python库,支持与OpenAI Realtime API进行实时音频交互。

功能特点

  • 基于WebRTC的实时音频通信
  • 支持OpenAI Realtime API
  • 自动音频设备管理
  • 自动采样率转换
  • 低延迟音频传输
  • 音频缓冲管理
  • 支持暂停/恢复流传输

安装要求

  • Python 3.7+
  • 支持的操作系统:Windows, macOS, Linux
  • 音频设备支持

依赖项

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

安装

  1. 克隆仓库:
git clone https://github.com/yourusername/openai-realtime-webrtc-python.git
cd openai-realtime-webrtc-python
  1. 创建虚拟环境:
python -m venv venv
source venv/bin/activate  # Linux/macOS

  1. 安装依赖:
pip install -r requirements.txt
  1. 开发模式安装:
pip install -e .

使用方法

  1. 设置环境变量: 创建 .env 文件并添加您的OpenAI API密钥:
OPENAI_API_KEY=your-api-key-here
  1. 基本使用示例:
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())
  1. 运行示例:
python examples/basic_streaming.py

贡献指南

欢迎提交 Pull Requests 和 Issues!

许可证

MIT License

更新日志

v0.1.0

  • 初始版本发布
  • 实现基本的WebRTC音频流功能
  • 支持OpenAI Realtime API
  • 自动音频设备管理
  • 音频重采样支持
MIT License Copyright (c) 2024 realtime-ai Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/sdfsadf/openai-realtime-webrtc-python.git
git@gitee.com:sdfsadf/openai-realtime-webrtc-python.git
sdfsadf
openai-realtime-webrtc-python
openai-realtime-webrtc-python
main

搜索帮助