diff --git a/dsLightRag/Config/Config.py b/dsLightRag/Config/Config.py index 3ce4db9f..f2d9d377 100644 --- a/dsLightRag/Config/Config.py +++ b/dsLightRag/Config/Config.py @@ -78,5 +78,7 @@ ACCESS_TOKEN_EXPIRE_MINUTES = 300000 # 访问令牌过期时间(分钟) # 火山引擎相关信息 # 语音识别 https://console.volcengine.com/speech/service/10012?AppID=1513532196 -HS_ASR_APP_ID="1513532196" -HS_ASR_TOKEN="ti2NW-kbjIbkzc6BK55actnI_wTR8xkH" \ No newline at end of file +HS_APP_ID= "1513532196" +HS_ACCESS_TOKEN= "ti2NW-kbjIbkzc6BK55actnI_wTR8xkH" +HS_CLUSTER_ID="volcano_tts" +HS_VOICE_TYPE = "zh_female_wanwanxiaohe_moon_bigtts" # 中文女声 湾湾小何 diff --git a/dsLightRag/Test/tts_http_demo.py b/dsLightRag/Test/tts_http_demo.py new file mode 100644 index 00000000..7e5cbfc9 --- /dev/null +++ b/dsLightRag/Test/tts_http_demo.py @@ -0,0 +1,60 @@ +#coding=utf-8 + +''' +requires Python 3.6 or later +pip install requests +''' +import base64 +import json +import uuid +import requests + +from Config.Config import HS_APP_ID, HS_ACCESS_TOKEN, HS_CLUSTER_ID, HS_VOICE_TYPE + +appid = HS_APP_ID +access_token= HS_ACCESS_TOKEN +cluster = HS_CLUSTER_ID + +voice_type = HS_VOICE_TYPE +host = "openspeech.bytedance.com" +api_url = f"https://{host}/api/v1/tts" + +header = {"Authorization": f"Bearer;{access_token}"} + +request_json = { + "app": { + "appid": appid, + "token": "access_token", + "cluster": cluster + }, + "user": { + "uid": "388808087185088" + }, + "audio": { + "voice_type": voice_type, + "encoding": "mp3", + "speed_ratio": 1.0, + "volume_ratio": 1.0, + "pitch_ratio": 1.0, + }, + "request": { + "reqid": str(uuid.uuid4()), + "text": "字节跳动语音合成", + "text_type": "plain", + "operation": "query", + "with_frontend": 1, + "frontend_type": "unitTson" + + } +} + +if __name__ == '__main__': + try: + resp = requests.post(api_url, json.dumps(request_json), headers=header) + print(f"resp body: \n{resp.json()}") + if "data" in resp.json(): + data = resp.json()["data"] + file_to_save = open("test_submit.mp3", "wb") + file_to_save.write(base64.b64decode(data)) + except Exception as e: + e.with_traceback() diff --git a/dsLightRag/Util/ASRClient.py b/dsLightRag/Util/ASRClient.py index de3662bd..a14d27af 100644 --- a/dsLightRag/Util/ASRClient.py +++ b/dsLightRag/Util/ASRClient.py @@ -3,13 +3,13 @@ import time import uuid import requests -from Config.Config import HS_ASR_APP_ID, HS_ASR_TOKEN +from Config.Config import HS_APP_ID, HS_ACCESS_TOKEN class ASRClient: def __init__(self, appid=None, token=None, file_url=None): - self.appid = appid or HS_ASR_APP_ID - self.token = token or HS_ASR_TOKEN + self.appid = appid or HS_APP_ID + self.token = token or HS_ACCESS_TOKEN self.file_url = file_url or "https://ttc-advisory-oss.oss-cn-hangzhou.aliyuncs.com/lark_audio/int/T_APLA_1941058348698869760.mp3" self.submit_url = "https://openspeech-direct.zijieapi.com/api/v3/auc/bigmodel/submit" self.query_url = "https://openspeech-direct.zijieapi.com/api/v3/auc/bigmodel/query"