STT流式输入业务逻辑处理

This commit is contained in:
2025-10-19 00:02:11 +08:00
parent d46581e1dc
commit d58fa13356
2 changed files with 10 additions and 6 deletions

View File

@@ -199,15 +199,15 @@ public class ChatWebSocketHandler {
log.info("获取的socket对象为:{}",webSocket);
if(webSocket != null){
// 1. 启动音频缓冲
webSocket.send("{\"type\": \"input_audio_buffer.start\"}");
// 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);
}

View File

@@ -81,8 +81,8 @@ public class RealtimeTranscriptionMicrophone {
}
// 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();
}