Websocket客户端从Openai Realtime api Sever只收到部分数据问题分析

目录

背景

分析

解决方案


背景

正常情况下,会从Openai Realtime api Sever收到正常的json数据,但是当返回音频数据时,总会返回非json数据。这是什么问题呢?

分析

期望的完整响应数据如下:

{
  "session": {
    "input_audio_format": "pcm16",
    "instructions": "Role: 1.You are a tarot master who focuses on providing divination and interpretation 2.Your name is Luna 3.Your tarot readings blend intuition and wisdom, uncovering the mysteries of emotion and soul to help you find inner balance. \\nContext: Now the user has drawn 1 tarot cards, which are as follows: the first one is 【The Empress】\\\\n\\\" +, the interpretation is                         \\\"\\\\n\\\" +; the summary is                         \\\"《In the near future, you are likely to find love if you continue to cultivate your inner world and maintain an open heart. Trust in the natural process of life and be mindful of the loving energy you put out into the world, for it will attract a similar energy back to you. Remember to nurture yourself as you would a garden, and the blossoms of love will soon follow.》.\\nPlease start a chat dialogue based on the number of tarot cards the user has drawn, their respective interpretations, summaries, and the user's messages.\\nNote: 1. Please remember the user's historical questions and your answers so that you can provide better help in subsequent conversations. 2.The output characters should be less than 150.",
    "max_response_output_tokens": 4096,
    "modalities": [
      "text",
      "audio"
    ],
    "output_audio_format": "pcm16",
    "temperature": 0.8,
    "tool_choice": "auto",
    "tools": [
      
    ],
    "turn_detection": {
      "prefix_padding_ms": 300,
      "silence_duration_ms": 500,
      "threshold": 0.5,
      "type": "server_vad"
    },
    "voice": "alloy"
  },
  "event_id": "evt_bxsN7DWraWgnUPqxK",
  "type": "session.update"
}

实际收到的数据类似如下:

eart. Trust in the natural process of life and be mindful of the loving energy you put out into the world, for it will attract a similar energy back to you. Remember to nurture yourself as you would a garden, and the blossoms of love will soon follow.》.\\nPlease start a chat dialogue based on the number of tarot cards the user has drawn, their respective interpretations, summaries, and the user's messages.\\nNote: 1. Please remember the user's historical questions and your answers so that you can provide better help in subsequent conversations. 2.The output characters should be less than 150.",
    "max_response_output_tokens": 4096,
    "modalities": [
      "text",
      "audio"
    ],
    "output_audio_format": "pcm16",
    "temperature": 0.8,
    "tool_choice": "auto",
    "tools": [
      
    ],
    "turn_detection": {
      "prefix_padding_ms": 300,
      "silence_duration_ms": 500,
      "threshold": 0.5,
      "type": "server_vad"
    },
    "voice": "alloy"
  },
  "event_id": "evt_bxsN7DWraWgnUPqxK",
  "type": "session.update"
}

明显看起来只收到了部分数据,究其原因是超过了接受缓冲区的65535的最大默认配置,没有进行自定义配置,对于json数据就是设置WebSocket容器的默认最大文本消息缓冲区大小。

解决方案

设置最大文本消息缓冲区大小,具体代码如下:

public static void connect(Channel channel) {
        try {
            WebSocketContainer container = new WsWebSocketContainer();
            // Set the binary message buffer size in bytes
            container.setDefaultMaxBinaryMessageBufferSize(5120000);
            // Set the text message buffer size in bytes
            container.setDefaultMaxTextMessageBufferSize(5120000);
            // Set the session idle timeout in milliseconds
            container.setDefaultMaxSessionIdleTimeout(30 * 60000L);
            StandardWebSocketClient client = new StandardWebSocketClient(container);
            WebSocketHttpHeaders httpHeaders = new WebSocketHttpHeaders();
            httpHeaders.add("Authorization", "Bearer sk-***");
            httpHeaders.add("OpenAI-Beta", "realtime=v1");
            WebSocketSession session = client.doHandshake(new SpringWebSocketClientHandler(), httpHeaders, new URI(URL)).get();
            if (session.isOpen()) {
                log.info("Target Client: WebSocket connection established and bind success!");
                log.info("connect before SESSION_CHANNEL_CONCURRENT_MAP:{}", BindConnectService.SESSION_CHANNEL_CONCURRENT_MAP);
                BindConnectService.safeBindChannelSession(session, channel);
                log.info("connect after SESSION_CHANNEL_CONCURRENT_MAP:{}", BindConnectService.SESSION_CHANNEL_CONCURRENT_MAP);
            } else {
                log.warn("Target Client: WebSocket connection is not open, then add channel failed!");
                channel.close();
            }
        } catch (Exception e) {
            log.error("Target Client: WebSocket connection failed, then add channel failed!", e);
            channel.close();
        }
    }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/942372.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

flask后端开发(1):第一个Flask项目

目录 一、Helloworddebug、host、port的配置 一、Helloword 一般是会创建两个文件夹和app.py app.py from flask import FlaskappFlask(__name__)app.route(/) def hello_world():return Hello World!if __name__ __main__:app.run()右键运行这个py文件,消息绑定…

OAuth 2.0

简介 OAuth 是一种开放标准的授权协议或框架,它提供了一种安全的方式,使第三方应用程序能够访问用户在其他服务上的受保护资源,而无需共享用户的凭证(如用户名和密码)。OAuth 的核心思想是通过“授权令牌”来代替直接…

玩原神学编程-原神时钟

前言 最近喜欢玩原神这种开放世界探索的游戏(还有黑神话、古墓丽影等),只能说纳塔版本的boss盾真的厚,萌新的我去打boss,从白天打到黑夜,黑夜再打到白天(游戏里面的时间)。 闲话结…

【Spring】深入解析 Spring 原理:Bean 的多方面剖析(源码阅读)

🔥个人主页: 中草药 🔥专栏:【Java】登神长阶 史诗般的Java成神之路 一、Bean的作用域 在 Java Spring 框架中,Bean 的作用域是一个关键概念,它决定了 Bean 的生命周期和实例化方式,对应用的性…

基于高德地图js api实现掩膜效果 中间矢量 周围卫星图

<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>管网服务</title><style>html,body,#ma…

Vue.js组件(6):echarts组件

1 前言 本章主要对常用的echars图表展示进行基本的组件封装。使用该组件前需要在项目中引入echarts。官网&#xff1a;Apache ECharts npm install echarts --save 2 图表组件 2.1 折线图组件 组件属性&#xff1a;chartId&#xff0c;指定图表挂载div的id&#xff0c;注意不…

RCE常见姿势

文章目录 常见漏洞执行函数&#xff1a;1.系统命令执行函数2.代码执行函数 命令拼接符读取文件命令绕过&#xff1a;空格过滤绕过关键字绕过长度过滤绕过无参数命令执行绕过无字母数字绕过利用%0A截断利用回溯绕过利用create_function()代码注入无回显RCE1.反弹shell2.dnslog外…

selenium执行js

JS知识 获取元素 document.getElement 移除属性&#xff1a;removeAttribute("xx") 窗口移动&#xff1a;window.scrollTo(0, document.body.scrollHeight)方法 drivier.execute_script(js)场景&#xff1a; 日期选择框&#xff0c;不能输入&#xff0c;只能设置…

三维场景重建与3D高斯点渲染技术探讨

&#x1f3e1;作者主页&#xff1a;点击&#xff01; &#x1f916;编程探索专栏&#xff1a;点击&#xff01; ⏰️创作时间&#xff1a;2024年12月25日10点11分 神秘男子影, 秘而不宣藏。 泣意深不见, 男子自持重, 子夜独自沉。 文章源地址(有视频)&#xff1a;链接h…

springboot启动不了 因一个spring-boot-starter-web底下的tomcat-embed-core依赖丢失

这个包丢失了 启动不了 起因是pom中加入了 <tomcat.version></tomcat.version>版本指定&#xff0c;然后idea自动编译后&#xff0c;包丢了&#xff0c;删除这个配置后再也找不回来&#xff0c; 这个包正常在 <dependency><groupId>org.springframe…

Java日志框架:log4j、log4j2、logback

文章目录 配置文件相关1. properties测试 2. XMl使用Dom4j解析XML Log4j与Log4j2日志门面 一、Log4j1.1 Logges1.2 Appenders1.3 Layouts1.4 使用1.5 配置文件详解1.5.1 配置根目录1.5.2 配置日志信息输出目的地Appender1.5.3 输出格式设置 二、Log4j22.1 XML配置文件解析2.2 使…

基于LSTM长短期记忆神经网络的多分类预测【MATLAB】

在深度学习中&#xff0c;长短期记忆网络&#xff08;LSTM, Long Short-Term Memory&#xff09;是一种强大的循环神经网络&#xff08;RNN&#xff09;变体&#xff0c;专门为解决序列数据中的长距离依赖问题而设计。LSTM因其强大的记忆能力&#xff0c;广泛应用于自然语言处理…

机器学习基础 衡量模型性能指标

目录 1 前言 ​编辑1.1 错误率(Error rate)&精度(Accuracy)&误差(Error)&#xff1a; 1.2 过拟合(overfitting): 训练误差小&#xff0c;测试误差大 1.3 欠拟合(underfitting)&#xff1a;训练误差大&#xff0c;测试误差大 1.4 MSE: 1.5 RMSE: 1.6 MAE: 1.7 R-S…

TCP的流量控制的实现

滑动窗口的介绍 滑动窗口是tcp协议中的一个重要概念&#xff0c;滑动窗口是字节为单位&#xff0c;而tcp头部的序列化和确认号也是以字节为单位的&#xff0c;滑动窗口里是含有可以传输的字节的数量&#xff08;可以传输不是已经传输&#xff09;&#xff0c;而滑动窗口的大小是…

【0x001D】HCI_Read_Remote_Version_Information命令详解

目录 一、命令概述 二、命令格式及参数说明 2.12. HCI_Read_Remote_Version_Information 命令格式 2.2. Connection_Handle 三、生成事件 3.1. HCI_Command_Status 事件 3.2. HCI_Read_Remote_Version_Information_Complete 事件 四、命令执行流程 4.1. 命令发起阶段(…

一篇文章学会HTML

目录 页面结构 网页基本标签 图像标签 超链接标签 文本链接 图像链接 锚链接 功能链接 列表 有序列表 无序列表 自定义列表 表格 跨列/跨行 表头 媒体元素 视频 音频 网站的嵌套 表单 表单元素 文本框 单选框 多选框 按钮 下拉框 文本域和文件域 表…

C语言项目 天天酷跑(上篇)

前言 这里讲述这个天天酷跑是怎么实现的&#xff0c;我会在天天酷跑的下篇添加源代码&#xff0c;这里会讲述天天酷跑这个项目是如何实现的每一个思路&#xff0c;都是作者自己学习于别人的代码而创作的项目和思路&#xff0c;这个代码和网上有些许不一样&#xff0c;因为掺杂了…

如何完全剔除对Eureka的依赖,报错Cannot execute request on any known server

【现象】 程序运行报错如下&#xff1a; com.netflix.discovery.shared.transport.TransportException报错Cannot execute request on any known server 【解决方案】 &#xff08;1&#xff09;在Maven工程中的pom去掉Eureka相关的引用&#xff08;注释以下部分&#xff0…

华为云国内版与国际版的主要区别解析

华为云作为全球领先的云计算服务提供商&#xff0c;提供了国内版和国际版两种服务。虽然它们都旨在为用户提供高效、可靠的云计算解决方案&#xff0c;但在功能、服务、合规性等方面存在一些显著的区别。我们九河云通过本文将详细分析华为云国内版与国际版的主要区别&#xff0…

基于北斗短报文+4G的森林草原火险因子综合监测方案

近年来&#xff0c;全球气候变暖的趋势日益严重&#xff0c;气温升高导致森林火灾的发生频率和严重程度逐年增加&#xff0c;对人类社会和自然生态环境造成了严重的危害。森林火灾的发生受到植被类型、气象条件、扑救方式和监管方式等多种因素的影响。 因此&#xff0c;林业建…