asr.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import asyncio
  2. import datetime
  3. import os
  4. import sys
  5. from typing import List, Optional
  6. sys.path.append(os.path.dirname(os.path.dirname(__file__)))
  7. import jwt
  8. from fastapi import FastAPI,APIRouter, HTTPException, Depends, Request,Header
  9. from fastapi import Depends, FastAPI, HTTPException, status
  10. from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
  11. from pydantic import BaseModel,Field
  12. from fastapi.responses import JSONResponse
  13. from config import *
  14. from api.swl_jwt import verify_jwt_token,verify_user
  15. from db.user import User,UserRepo
  16. from tool import funasr_wss_client,video_get
  17. # ASR(Automatic Speech Recognition)语音识别
  18. asr_router = APIRouter()
  19. class AsrPostData(BaseModel):
  20. string: str = Field(..., description="获取视频无水印下载连接,可以是视频地址、分享链接",
  21. example="4.30 03/30 bNJ:/ L@w.FH 踩中风口真的可以翻身吗?从一穷二白到AI逆袭,他怎么做到的? # 东方对话 # 人工智能 # ai https://v.douyin.com/i8Df1CC/ 复制此链接,打开Dou音搜索,直接观看视频!")
  22. @asr_router.post("/asr")
  23. async def asr(data:AsrPostData, user: User = Depends(verify_user)):
  24. save_dir = os.path.join(TEMP_DIR, "asr", user.open_id, "")
  25. save_path = await video_get.download_video_by_share_link(data.string, )
  26. return {"message": "ASR处理成功"}
  27. @asr_router.post("/video_get_download_url")
  28. async def video_get_download_url(data:AsrPostData, user: User = Depends(verify_user)):
  29. return await video_get.get_video_download_urls(data.string)