text stringlengths 0 93.6k |
|---|
@app.post("/simple_asr") |
async def simple_asr(file: UploadFile = File(...)): |
"""语音转文字""" |
try: |
# 读取文件内容为字节流, audio_bytes文件类型为:<class 'bytes'> |
audio = await file.read() |
recognized_text = auto_asr.transcription(audio) |
return JSONResponse( |
content={"code": 0, "msg": "ASR识别成功", "data": {"recognized_text": recognized_text}}, |
status_code=200 |
) |
except Exception as e: |
logger.error(f"错误信息为: {str(e)}") |
return JSONResponse( |
content={"code": 1, "msg": "识别失败", "data": {"recognized_text": ''}}, |
status_code=400 |
) |
if __name__ == "__main__": |
import uvicorn |
try: |
uvicorn.run(app, host="0.0.0.0", port=8847) |
except Exception as e: |
logger.error(f"启动服务器时出错: {e}") |
# <FILESEP> |
#!/usr/bin/python |
# pylint: disable=invalid-name |
''' |
plugin_test. |
This is a test and demonstration of using the d-rats plugin feature. |
''' |
import argparse |
import gettext |
import logging |
import time |
from xmlrpc.client import Fault |
from xmlrpc.client import ServerProxy |
# This makes pylance happy with out overriding settings |
# from the invoker of the classes and methods in this module. |
if not '_' in locals(): |
_ = gettext.gettext |
# pylint wants at least 2 public methods |
# pylint: disable=too-few-public-methods |
class PluginProxy: |
''' |
Plugin Proxy Client. |
:param server: D-rats plugin server address |
:type server: str |
:param port: D-Rats plugin server port |
:type port: int |
''' |
def __init__(self, server, port): |
pluginsrv = "http://%s:%i" % (server, port) |
self.server = ServerProxy(pluginsrv) |
def wait_for_result(self, ident, count=10, delay=5): |
''' |
Wait for result. |
:param ident: identification of RPC job |
:type ident: int |
:param count: Number of times to poll for result, default 10 |
:type count: int |
:param delay: Delay time in seconds |
:type delay: float |
:returns: Result of call |
:rtype: dict |
''' |
while count > 0: |
count -= 1 |
time.sleep(delay) |
result = self.server.get_result(ident) |
if result: |
break |
return result |
def main(): |
'''Plugin test Main module.''' |
gettext.install("D-RATS") |
lang = gettext.translation("D-RATS", |
localedir="locale", |
fallback=True) |
lang.install() |
# pylint: disable=global-statement |
global _ |
_ = lang.gettext |
# pylint: disable=too-few-public-methods |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.