mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 16:43:55 +08:00
Merge pull request #1199 from whosmyqueen/feature/add-fun-asr-auth
[feature] 添加FunServerAsr认证
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
-- 更新模型供应器表
|
||||||
|
UPDATE `ai_model_provider` SET fields = '[{"key": "host", "type": "string", "label": "服务地址"}, {"key": "port", "type": "number", "label": "端口号"}, {"key": "api_key", "type": "string", "label": "API密钥"}]' WHERE id = 'SYSTEM_ASR_FunASRServer';
|
||||||
|
|
||||||
|
-- 更新模型配置表
|
||||||
|
UPDATE `ai_model_config` SET config_json = '{"host": "127.0.0.1", "port": 10096, "type": "fun_server", "api_key": "none"}' WHERE id = 'ASR_FunASRServer';
|
||||||
@@ -114,10 +114,17 @@ databaseChangeLog:
|
|||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202505091409.sql
|
path: classpath:db/changelog/202505091409.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505091552
|
||||||
|
author: whosmyqueen
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505091552.sql
|
||||||
- changeSet:
|
- changeSet:
|
||||||
id: 202505111914
|
id: 202505111914
|
||||||
author: hrz
|
author: hrz
|
||||||
changes:
|
changes:
|
||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202505111914.sql
|
path: classpath:db/changelog/202505111914.sql
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import wave
|
|||||||
import websockets
|
import websockets
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import re
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
logger = setup_logging()
|
logger = setup_logging()
|
||||||
@@ -24,6 +25,7 @@ class ASRProvider(ASRProviderBase):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.host = config.get("host", "localhost")
|
self.host = config.get("host", "localhost")
|
||||||
self.port = config.get("port", 10095)
|
self.port = config.get("port", 10095)
|
||||||
|
self.api_key = config.get('api_key', 'none')
|
||||||
self.is_ssl = config.get("is_ssl", True)
|
self.is_ssl = config.get("is_ssl", True)
|
||||||
self.output_dir = config.get("output_dir")
|
self.output_dir = config.get("output_dir")
|
||||||
self.delete_audio_file = delete_audio_file
|
self.delete_audio_file = delete_audio_file
|
||||||
@@ -130,9 +132,9 @@ class ASRProvider(ASRProviderBase):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
file_path = self.save_audio_to_file(pcm_data, session_id)
|
file_path = self.save_audio_to_file(pcm_data, session_id)
|
||||||
|
auth_header = {'Authorization': 'Bearer; {}'.format(self.api_key)}
|
||||||
async with websockets.connect(
|
async with websockets.connect(
|
||||||
self.uri, subprotocols=["binary"], ping_interval=None, ssl=self.ssl_context
|
self.uri, additional_headers=auth_header, subprotocols=["binary"], ping_interval=None, ssl=self.ssl_context
|
||||||
) as ws:
|
) as ws:
|
||||||
try:
|
try:
|
||||||
# Use asyncio to handle WebSocket communication
|
# Use asyncio to handle WebSocket communication
|
||||||
@@ -157,6 +159,9 @@ class ASRProvider(ASRProviderBase):
|
|||||||
|
|
||||||
# Get the result from the receive task
|
# Get the result from the receive task
|
||||||
result = receive_task.result()
|
result = receive_task.result()
|
||||||
|
match = re.match(r'<\|(.*?)\|><\|(.*?)\|><\|(.*?)\|>(.*)', result)
|
||||||
|
if match:
|
||||||
|
result = match.group(4).strip()
|
||||||
return (
|
return (
|
||||||
result,
|
result,
|
||||||
file_path,
|
file_path,
|
||||||
|
|||||||
Reference in New Issue
Block a user