-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: tti model #2060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: tti model #2060
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,14 @@ | |
| import hmac | ||
| import json | ||
| import os | ||
| import ssl | ||
| import uuid | ||
| import wave | ||
| from enum import Enum | ||
| from hashlib import sha256 | ||
| from io import BytesIO | ||
| from typing import Dict | ||
| from urllib.parse import urlparse | ||
| import ssl | ||
|
|
||
| import websockets | ||
|
|
||
| from setting.models_provider.base_model_provider import MaxKBBaseModel | ||
|
|
@@ -305,7 +305,8 @@ async def segment_data_processor(self, wav_data: bytes, segment_size: int): | |
| res = await ws.recv() | ||
| result = parse_response(res) | ||
| if 'payload_msg' in result and result['payload_msg']['code'] != self.success_code: | ||
| raise Exception(f"Error code: {result['payload_msg']['code']}, message: {result['payload_msg']['message']}") | ||
| raise Exception( | ||
| f"Error code: {result['payload_msg']['code']}, message: {result['payload_msg']['message']}") | ||
| for seq, (chunk, last) in enumerate(VolcanicEngineSpeechToText.slice_data(wav_data, segment_size), 1): | ||
| # if no compression, comment this line | ||
| payload_bytes = gzip.compress(chunk) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet is mostly clean and follows standard Python conventions. However, there are a few minor issues and potential improvements that can be considered:
Here’s the revised version with these considerations addressed: @@ -12,14 +12,14 @@
import hmac
import json
import os
+import ssl
import uuid
import wave
from enum import Enum
from hashlib import sha256
from io import BytesIO
from typing import Dict
from urllib.parse import urlparse
-import ssl
+
import websockets
from setting.models_provider.base_model_provider import MaxKBBaseModel
@@ -305,7 +305,8 @@ async def segment_data_processor(self, wav_data: bytes, segment_size: int):
res = await ws.recv()
result = parse_response(res)
if 'payload_msg' in result and result['payload_msg']['code'] != self.success_code:
- raise Exception(f"Error code: {result['payload_msg']['code']}, message: {result['payload_msg']['message']}")
+ error_message = f"Error code: {result['payload_msg']['code']}, message: {result['payload_msg']['message']}"
+ raise Exception(error_message)
for seq, (chunk, last) in enumerate(VolcanicEngineSpeechToText.slice_data(wav_data, segment_size), 1):
# if no compression, comment this line
payload_bytes = gzip.compress(chunk)Additional Suggestion for Handling Connection IssuesIt would also be wise to implement some basic error handling around the WebSocket connection, such as checking if the connection was closed gracefully during reception and possibly retrying a reconnection if needed: async def receive_messages(self, ws):
try:
while True:
msg = await ws.recv()
result = parse_response(msg)
if 'payload_msg' in result:
if result['payload_msg']['code'] == self.success_code:
handle_successful_result(result)
else:
log_error(result['payload_msg'])
else:
log_malformed_response(msg)
except asyncio.IncompleteReadError:
logging.error("Unexpectedly disconnected.")
finally:
await ws.close()
# Usage: self.websocket_coroutine = asyncio.create_task(receive_messages(websocket))By making these changes, you improve both the readability and robustness of your codebase. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,17 +11,17 @@ | |
| import hmac | ||
| import json | ||
| import logging | ||
| import os | ||
| import ssl | ||
| from datetime import datetime, UTC | ||
| from typing import Dict | ||
| from urllib.parse import urlencode, urlparse | ||
| import ssl | ||
|
|
||
| import websockets | ||
| from django.utils.translation import gettext as __ | ||
|
|
||
| from common.util.common import _remove_empty_lines | ||
| from setting.models_provider.base_model_provider import MaxKBBaseModel | ||
| from setting.models_provider.impl.base_tts import BaseTextToSpeech | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
|
||
| max_kb = logging.getLogger("max_kb") | ||
|
|
||
|
|
@@ -98,7 +98,7 @@ def create_url(self): | |
| return url | ||
|
|
||
| def check_auth(self): | ||
| self.text_to_speech(_('Hello')) | ||
| self.text_to_speech(__('Hello')) | ||
|
|
||
| def text_to_speech(self, text): | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet seems to have a few minor issues that can be addressed:
Here’s the corrected version of the code with these improvements: @@ -11,16 +11,16 @@ import hmac
import json
import logging
import os
+ ssl # Removed duplicate import
from datetime import datetime, UTC
from typing import Dict
from urllib.parse import urlencode, urlparse
from django.utils.translation import gettext_lazy as _
max_kb = logging.getLogger("max_kb")
def create_url(self):
scheme_port = 'http'
if self.ssl_enabled:
scheme_port = 'https'
base_url = "{}://{}:{}/api".format(scheme_port, self.host, self.port)
path_params = {"token": self.token}
params_str = "?" + urlencode(path_params) if path_params else ""
return "".join([base_url, "/", self.request_path, params_str])
def check_auth(self):
self.text_to_speech(_("Hello"))
def text_to_speech(self, text):
# Placeholder for actual implementation
passExplanation of Changes:
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an issue with the import statements. The
AIMessageChunkclass seems to be missing from the imported modules. Additionally,_convert_delta_to_messag_chunkfunction can cause issues if the base message object is not provided correctly due to potential inconsistencies between LangChain versions.Here's a revised version of your code:
Optimization Suggestions:
CallbackManagerForLLMRun,get_buffer_string), you can remove them to simplify imports.Typing.Anyis considered outdated. You might want to use more specific type hints wherever applicable._convert_delta_to_message_chunkare called appropriately without causing issues related to argument types or missing attributes.Make sure that this revision meets your functional requirements and adheres to best practices for using PyPI package management.