refactor: 豆包接口校验发送demo验证
This commit is contained in:
parent
467b864895
commit
f906efa9e2
Binary file not shown.
@ -11,6 +11,7 @@ import base64
|
|||||||
import gzip
|
import gzip
|
||||||
import hmac
|
import hmac
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import wave
|
import wave
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
@ -144,6 +145,7 @@ def parse_response(res):
|
|||||||
result['code'] = code
|
result['code'] = code
|
||||||
payload_size = int.from_bytes(payload[4:8], "big", signed=False)
|
payload_size = int.from_bytes(payload[4:8], "big", signed=False)
|
||||||
payload_msg = payload[8:]
|
payload_msg = payload[8:]
|
||||||
|
print(f"Error code: {code}, message: {payload_msg}")
|
||||||
if payload_msg is None:
|
if payload_msg is None:
|
||||||
return result
|
return result
|
||||||
if message_compression == GZIP:
|
if message_compression == GZIP:
|
||||||
@ -321,14 +323,9 @@ class VolcanicEngineSpeechToText(MaxKBBaseModel, BaseSpeechToText):
|
|||||||
return result['payload_msg']['result'][0]['text']
|
return result['payload_msg']['result'][0]['text']
|
||||||
|
|
||||||
def check_auth(self):
|
def check_auth(self):
|
||||||
header = self.token_auth()
|
cwd = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
with open(f'{cwd}/iat_mp3_16k.mp3', 'rb') as f:
|
||||||
async def check():
|
self.speech_to_text(f)
|
||||||
async with websockets.connect(self.volcanic_api_url, extra_headers=header, max_size=1000000000,
|
|
||||||
ssl=ssl_context) as ws:
|
|
||||||
pass
|
|
||||||
|
|
||||||
asyncio.run(check())
|
|
||||||
|
|
||||||
def speech_to_text(self, file):
|
def speech_to_text(self, file):
|
||||||
data = file.read()
|
data = file.read()
|
||||||
|
|||||||
@ -69,14 +69,7 @@ class VolcanicEngineTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def check_auth(self):
|
def check_auth(self):
|
||||||
header = self.token_auth()
|
self.text_to_speech('你好')
|
||||||
|
|
||||||
async def check():
|
|
||||||
async with websockets.connect(self.volcanic_api_url, extra_headers=header, ping_interval=None,
|
|
||||||
ssl=ssl_context) as ws:
|
|
||||||
pass
|
|
||||||
|
|
||||||
asyncio.run(check())
|
|
||||||
|
|
||||||
def text_to_speech(self, text):
|
def text_to_speech(self, text):
|
||||||
request_json = {
|
request_json = {
|
||||||
@ -159,7 +152,7 @@ class VolcanicEngineTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
if message_compression == 1:
|
if message_compression == 1:
|
||||||
error_msg = gzip.decompress(error_msg)
|
error_msg = gzip.decompress(error_msg)
|
||||||
error_msg = str(error_msg, "utf-8")
|
error_msg = str(error_msg, "utf-8")
|
||||||
break
|
raise Exception(f"Error code: {code}, message: {error_msg}")
|
||||||
elif message_type == 0xc:
|
elif message_type == 0xc:
|
||||||
msg_size = int.from_bytes(payload[:4], "big", signed=False)
|
msg_size = int.from_bytes(payload[:4], "big", signed=False)
|
||||||
payload = payload[4:]
|
payload = payload[4:]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user