STT流式输入业务逻辑处理
This commit is contained in:
@@ -198,16 +198,16 @@ public class ChatWebSocketHandler {
|
||||
WebSocket webSocket = cacheWebSocket.get(clientId);
|
||||
log.info("获取的socket对象为:{}",webSocket);
|
||||
if(webSocket != null){
|
||||
// 1. 启动音频缓冲
|
||||
webSocket.send("{\"type\": \"input_audio_buffer.start\"}");
|
||||
// 1. 启动音频缓冲
|
||||
// webSocket.send("{\"type\": \"input_audio_buffer.start\"}");
|
||||
log.info("3.1 开始发送数据音频流啦");
|
||||
// 将音频数据转换为 Base64 编码的字符串
|
||||
String base64Audio = Base64.getEncoder().encodeToString(bytes);
|
||||
String message = "{ \"type\": \"input_audio_buffer.append\", \"audio\": \"" + base64Audio + "\" }";
|
||||
webSocket.send(message);
|
||||
// 3. 提交音频并请求转录
|
||||
webSocket.send("{\"type\": \"input_audio_buffer.commit\"}");
|
||||
webSocket.send("{\"type\": \"response.create\"}");
|
||||
// webSocket.send("{\"type\": \"input_audio_buffer.commit\"}");
|
||||
// webSocket.send("{\"type\": \"response.create\"}");
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
@@ -326,6 +326,10 @@ public class ChatWebSocketHandler {
|
||||
config.put("type", "transcription_session.update");
|
||||
config.put("session", sessionConfig);
|
||||
webSocket.send(config.toString());
|
||||
|
||||
// 1. 启动音频缓冲
|
||||
webSocket.send("{\"type\": \"input_audio_buffer.start\"}");
|
||||
|
||||
//存储客户端webSocket对象,对数据进行隔离处理
|
||||
cacheWebSocket.put(clientId,webSocket);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user