TTS 返回语音优化

This commit is contained in:
2025-10-19 19:48:47 +08:00
parent 9febb08b4f
commit 100b3b2845
2 changed files with 9 additions and 14 deletions

View File

@@ -6,31 +6,26 @@ import cn.hutool.json.JSONUtil;
import com.vetti.common.ai.elevenLabs.ElevenLabsClient;
import com.vetti.common.ai.gpt.OpenAiStreamClient;
import com.vetti.common.ai.gpt.service.OpenAiStreamListenerService;
import com.vetti.common.ai.whisper.WhisperClient;
import com.vetti.common.config.RuoYiConfig;
import com.vetti.common.utils.spring.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.sound.sampled.*;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import javax.sound.sampled.*;
import java.io.*;
import java.nio.ByteBuffer;
/**
* 语音面试 web处理器
@@ -117,8 +112,8 @@ public class ChatWebSocketHandler {
//发送消息
WebSocket webSocket = cacheWebSocket.get(clientId);
webSocket.send("{\"type\": \"input_audio_buffer.commit\"}");
webSocket.send("{\"type\": \"response.create\"}");
// webSocket.send("{\"type\": \"input_audio_buffer.commit\"}");
// webSocket.send("{\"type\": \"response.create\"}");
// if(webSocket != null){
// webSocket.close(1000,null);
// }
@@ -362,7 +357,7 @@ public class ChatWebSocketHandler {
webSocket.send(config.toString());
// 1. 启动音频缓冲
webSocket.send("{\"type\": \"input_audio_buffer.start\"}");
// webSocket.send("{\"type\": \"input_audio_buffer.start\"}");
//存储客户端webSocket对象,对数据进行隔离处理
cacheWebSocket.put(clientId,webSocket);

View File

@@ -57,7 +57,7 @@ public class RealtimeTranscriptionMicrophone {
webSocket.send(config.toString());
// 1. 启动音频缓冲
webSocket.send("{\"type\": \"input_audio_buffer.start\"}");
// webSocket.send("{\"type\": \"input_audio_buffer.start\"}");
// 2. 开始录音并实时发送
new Thread(() -> {