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