From 78af9a0d61dbd491931ec225651a1fb120acb34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cweifeng2333=E2=80=9D?= <“2715673327@qq.com”> Date: Tue, 15 Oct 2024 12:56:41 +0800 Subject: [PATCH] update readme --- bk_asr/JianYingASR.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/bk_asr/JianYingASR.py b/bk_asr/JianYingASR.py index f10f5c4..142ad6b 100644 --- a/bk_asr/JianYingASR.py +++ b/bk_asr/JianYingASR.py @@ -4,11 +4,9 @@ import json import logging import os -import subprocess import time -from typing import Dict, Tuple, Literal +from typing import Dict, Tuple -# import ffmpeg import requests from .ASRData import ASRDataSeg @@ -91,12 +89,33 @@ def _make_segments(self, resp_data: dict) -> list[ASRDataSeg]: @staticmethod def _generate_sign_parameters(url: str, pf: str = '4', appvr: str = '4.0.0', tdid: str = '3943278516897751') -> \ Tuple[str, str]: - """Generate signature and timestamp""" + """Generate signature and timestamp via an HTTP request""" current_time = str(int(time.time())) - sign_str = f"9e2c|{url[-7:]}|{pf}|{appvr}|{current_time}|{tdid}|11ac" - sign = hashlib.md5(sign_str.encode()).hexdigest() + data = { + 'url': url, + 'current_time': current_time, + 'pf': pf, + 'appvr': appvr, + 'tdid': tdid + } + # Replace with your actual endpoint URL + get_sign_url = 'https://asrtools-update.bkfeng.top/sign' + try: + response = requests.post(get_sign_url, json=data) + response.raise_for_status() + response_data = response.json() + sign = response_data.get('sign') + if not sign: + raise ValueError("No 'sign' in response") + except requests.exceptions.RequestException as e: + raise SystemExit(f"HTTP Request failed: {e}") + except ValueError as ve: + raise SystemExit(f"Invalid response: {ve}") + print(f"Generated sign: {sign}") return sign.lower(), current_time + + def _build_headers(self, device_time: str, sign: str) -> Dict[str, str]: """Build headers for requests""" return {