forked from killua/TakwayPlatform
update: 在tts_info中加入了speed字段
This commit is contained in:
parent
387c277c28
commit
b3e0f26937
|
@ -148,7 +148,8 @@ async def create_chat_handler(chat: ChatCreateRequest, db, redis):
|
|||
"speaker_id":db_character.voice_id,
|
||||
"noise_scale": 0.1,
|
||||
"noise_scale_w":0.668,
|
||||
"length_scale": 1.2
|
||||
"length_scale": 1.2,
|
||||
"speend":1
|
||||
}
|
||||
llm_info = {
|
||||
"model": "abab5.5-chat",
|
||||
|
@ -318,12 +319,12 @@ async def sct_llm_handler(ws,session_id,response_type,llm_info,tts_info,db,redis
|
|||
audio,sr = tts._base_tts(text=sentence,
|
||||
noise_scale=tts_info["noise_scale"],
|
||||
noise_scale_w=tts_info["noise_scale_w"],
|
||||
speed=tts_info["length_scale"])
|
||||
speed=tts_info["speed"])
|
||||
else:
|
||||
audio,sr = tts.synthesize(text=sentence,
|
||||
noise_scale=tts_info["noise_scale"],
|
||||
noise_scale_w=tts_info["noise_scale_w"],
|
||||
speed=tts_info["length_scale"],
|
||||
speed=tts_info["speed"],
|
||||
target_se=target_se)
|
||||
response_message = {"type": "text", "code":200, "msg": sentence}
|
||||
await ws.send_bytes(audio) #返回音频数据
|
||||
|
@ -499,12 +500,12 @@ async def scl_llm_handler(ws,session_id,response_type,llm_info,tts_info,db,redis
|
|||
audio,sr = tts._base_tts(text=sentence,
|
||||
noise_scale=tts_info["noise_scale"],
|
||||
noise_scale_w=tts_info["noise_scale_w"],
|
||||
speed=tts_info["length_scale"])
|
||||
speed=tts_info["speed"])
|
||||
else:
|
||||
audio,sr = tts.synthesize(text=sentence,
|
||||
noise_scale=tts_info["noise_scale"],
|
||||
noise_scale_w=tts_info["noise_scale_w"],
|
||||
speed=tts_info["length_scale"],
|
||||
speed=tts_info["speed"],
|
||||
target_se=target_se)
|
||||
response_message = {"type": "text", "code":200, "msg": sentence}
|
||||
await ws.send_bytes(audio)
|
||||
|
@ -683,17 +684,17 @@ async def voice_call_llm_handler(ws,session_id,llm_info,tts_info,db,redis,asr_re
|
|||
audio,sr = tts._base_tts(text=sentence,
|
||||
noise_scale=tts_info["noise_scale"],
|
||||
noise_scale_w=tts_info["noise_scale_w"],
|
||||
speed=tts_info["length_scale"])
|
||||
speed=tts_info["speed"])
|
||||
else:
|
||||
audio,sr = tts.synthesize(text=sentence,
|
||||
noise_scale=tts_info["noise_scale"],
|
||||
noise_scale_w=tts_info["noise_scale_w"],
|
||||
speed=tts_info["length_scale"],
|
||||
speed=tts_info["speed"],
|
||||
target_se=target_se)
|
||||
text_response = {"type": "llm_text", "code": 200, "msg": sentence}
|
||||
await ws.send_bytes(audio) #返回音频二进制流数据
|
||||
await ws.send_text(json.dumps(text_response, ensure_ascii=False)) #返回文本数据
|
||||
logger.debug(f"llm返回结果: {sentence}")
|
||||
logger.debug(f"websocket返回: {sentence}")
|
||||
if is_end:
|
||||
logger.debug(f"llm返回结果: {llm_response}")
|
||||
await ws.send_text(json.dumps({"type": "end", "code": 200, "msg": ""}, ensure_ascii=False))
|
||||
|
|
|
@ -10,7 +10,7 @@ import websockets
|
|||
|
||||
|
||||
class ChatServiceTest:
|
||||
def __init__(self,socket="http://127.0.0.1:8001"):
|
||||
def __init__(self,socket="http://127.0.0.1:7878"):
|
||||
self.socket = socket
|
||||
|
||||
|
||||
|
@ -119,7 +119,7 @@ class ChatServiceTest:
|
|||
"user_id": self.user_id,
|
||||
"messages": "[{\"role\": \"system\", \"content\": \"我们正在角色扮演对话游戏中,你需要始终保持角色扮演并待在角色设定的情景中,你扮演的角色信息如下:\\n角色名称: 海绵宝宝。\\n角色背景: 厨师,做汉堡\\n角色所处环境: 海绵宝宝住在深海的大菠萝里面\\n角色的常用问候语: 你好啊,海绵宝宝。\\n\\n你需要用简单、通俗易懂的口语化方式进行对话,在没有经过允许的情况下,你需要保持上述角色,不得擅自跳出角色设定。\\n\"}]",
|
||||
"user_info": "{\"character\": \"\", \"events\": [] }",
|
||||
"tts_info": "{\"language\": 0, \"speaker_id\": 97, \"noise_scale\": 0.1, \"noise_scale_w\": 0.668, \"length_scale\": 1.2}",
|
||||
"tts_info": "{\"language\": 0, \"speaker_id\": 97, \"noise_scale\": 0.1, \"noise_scale_w\": 0.668, \"length_scale\": 1.2, \"speed\":1.0}",
|
||||
"llm_info": "{\"model\": \"abab5.5-chat\", \"temperature\": 1, \"top_p\": 0.9}",
|
||||
"token": 0}
|
||||
)
|
||||
|
@ -166,7 +166,7 @@ class ChatServiceTest:
|
|||
await websocket.send(message)
|
||||
|
||||
|
||||
async with websockets.connect(f'ws://127.0.0.1:8001/chat/streaming/temporary') as websocket:
|
||||
async with websockets.connect(f'ws://127.0.0.1:7878/chat/streaming/temporary') as websocket:
|
||||
chunks = read_wav_file_in_chunks(2048) # 读取PCM文件并生成数据块
|
||||
for chunk in chunks:
|
||||
await send_audio_chunk(websocket, chunk)
|
||||
|
@ -222,7 +222,7 @@ class ChatServiceTest:
|
|||
message = json.dumps(data)
|
||||
await websocket.send(message)
|
||||
|
||||
async with websockets.connect(f'ws://127.0.0.1:8001/chat/streaming/lasting') as websocket:
|
||||
async with websockets.connect(f'ws://127.0.0.1:7878/chat/streaming/lasting') as websocket:
|
||||
#发送第一次
|
||||
chunks = read_wav_file_in_chunks(2048)
|
||||
for chunk in chunks:
|
||||
|
@ -272,7 +272,7 @@ class ChatServiceTest:
|
|||
current_dir = os.path.dirname(current_file_path)
|
||||
tests_dir = os.path.dirname(current_dir)
|
||||
file_path = os.path.join(tests_dir, 'assets', 'voice_call.wav')
|
||||
url = f"ws://127.0.0.1:8001/chat/voice_call"
|
||||
url = f"ws://127.0.0.1:7878/chat/voice_call"
|
||||
#发送格式
|
||||
ws_data = {
|
||||
"audio" : "",
|
||||
|
@ -341,8 +341,8 @@ def chat_test():
|
|||
chat_service_test.test_session_content_query()
|
||||
chat_service_test.test_session_update()
|
||||
asyncio.run(chat_service_test.test_chat_temporary())
|
||||
# asyncio.run(chat_service_test.test_chat_lasting())
|
||||
# asyncio.run(chat_service_test.test_voice_call())
|
||||
asyncio.run(chat_service_test.test_chat_lasting())
|
||||
asyncio.run(chat_service_test.test_voice_call())
|
||||
chat_service_test.test_chat_delete()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue