update:优化ASR_FunASRServer文档

This commit is contained in:
hrz
2025-05-13 15:18:23 +08:00
parent 5987488b3d
commit 811bd94934
5 changed files with 32 additions and 13 deletions
@@ -25,8 +25,12 @@ class ASRProvider(ASRProviderBase):
super().__init__()
self.host = config.get("host", "localhost")
self.port = config.get("port", 10095)
self.api_key = config.get('api_key', 'none')
self.is_ssl = config.get("is_ssl", True)
self.api_key = config.get("api_key", "none")
self.is_ssl = str(config.get("is_ssl", True)).lower() in (
"true",
"1",
"yes",
)
self.output_dir = config.get("output_dir")
self.delete_audio_file = delete_audio_file
self.uri = (
@@ -132,9 +136,13 @@ class ASRProvider(ASRProviderBase):
pass
else:
file_path = self.save_audio_to_file(pcm_data, session_id)
auth_header = {'Authorization': 'Bearer; {}'.format(self.api_key)}
auth_header = {"Authorization": "Bearer; {}".format(self.api_key)}
async with websockets.connect(
self.uri, additional_headers=auth_header, 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:
try:
# Use asyncio to handle WebSocket communication
@@ -159,7 +167,7 @@ class ASRProvider(ASRProviderBase):
# Get the result from the receive task
result = receive_task.result()
match = re.match(r'<\|(.*?)\|><\|(.*?)\|><\|(.*?)\|>(.*)', result)
match = re.match(r"<\|(.*?)\|><\|(.*?)\|><\|(.*?)\|>(.*)", result)
if match:
result = match.group(4).strip()
return (