Datasets:
License:
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
import argparse | |
import base64 | |
import json | |
import os | |
import sys | |
pwd = os.path.abspath(os.path.dirname(__file__)) | |
sys.path.append(os.path.join(pwd, "../../")) | |
import numpy as np | |
import requests | |
class AgentXVoice(object): | |
""" | |
distil-whisper/distil-large-v3 | |
""" | |
def __init__(self, | |
api_key: str, | |
url_host: str = "https://api.agentx.so" | |
): | |
self.api_key = api_key | |
self.url_host = url_host | |
def do_asr_by_ndarray(self, signal: np.ndarray, language: str): | |
pcm_signal = signal.tobytes() | |
pcm_in_base64 = base64.b64encode(pcm_signal).decode("utf-8") | |
return self.do_asr_by_base64(pcm_in_base64, language) | |
def do_asr_by_file(self, filename: str, language: str): | |
with open(filename, "rb") as f: | |
data = f.read() | |
base64string = base64.b64encode(data).decode("utf-8") | |
return self.do_asr_by_base64(base64string, language) | |
def do_asr_by_base64(self, signal_base64: str, language: str): | |
url = "{}/api/v1/voiceApi/asr/recognize/do_asr".format(self.url_host) | |
headers = { | |
"Content-type": "application/json", | |
"x-api-key": self.api_key | |
} | |
data = { | |
"callID": "string", | |
"seqID": "string", | |
"callbackUrl": "string", | |
"sampleInBase64": signal_base64, | |
"sampleDuration": "string", | |
"language": language, | |
"other": "string" | |
} | |
resp = requests.request( | |
"POST", | |
url=url, | |
headers=headers, | |
data=json.dumps(data) | |
) | |
if resp.status_code != 200: | |
raise AssertionError("status_code: {}, text: {}".format(resp.status_code, resp.text)) | |
js = resp.json() | |
return js | |
if __name__ == '__main__': | |
pass | |