Documentation ¶
Overview ¶
语音转写 Long Form Automatic Speech Recognition 如果不使用 NewXfyun,必须先 SetLfAsrSecret 设置语音转写密钥 上传音视频文件,可以设置处理结果回调,再调用结果查询接口 https://www.xfyun.cn/doc/asr/ifasr_new/API.html
Index ¶
- Constants
- Variables
- func Unmarshal(res *resty.Response, body ResBodyI) error
- type Cw
- type ErrFail
- type GetResultRes
- type Json1best
- type Lattice
- type Lattice2
- type LfAsr
- func (a LfAsr) GetResult(orderId string) (*GetResultRes, error)
- func (a LfAsr) OrderResult(res *GetResultRes) (string, error)
- func (a LfAsr) Sentence(las []Lattice)
- func (a LfAsr) SignA(secret string) map[string]string
- func (a LfAsr) SpeechToText(name string, timeout time.Duration) (string, error)
- func (a LfAsr) Srt(las []Lattice) (string, error)
- func (a LfAsr) Upload(name string) (*UploadRes, error)
- func (a LfAsr) UploadCallback(c *gin.Context)
- func (a LfAsr) Valid() error
- func (a LfAsr) VideoTime(msec string) (string, error)
- type OrderResult
- type ResBody
- type ResBodyI
- type Rt
- type St
- type UploadRes
- type Ws
Constants ¶
View Source
const ( // 文件上传地址 UrlUpload = "https://raasr.xfyun.cn/v2/api/upload" // 获取结果地址 UrlGetResult = "https://raasr.xfyun.cn/v2/api/getResult" )
View Source
const ( OrderStatusCreated = 0 // 已创建 OrderStatusProcess = 3 // 处理中 OrderStatusComplete = 4 // 处理完成-成功 OrderStatusFailed = -1 // 处理完成-失败 )
订单流程状态
View Source
const ( WpNormal = "n" // 正常词 WpSmooth = "s" // 顺滑 WpPunct = "p" // 标点 WpSeg = "g" // 分段标识,对应Cw.W为空 )
词语类型
View Source
const ResCodeSuss = "000000"
响应成功时,才能获取到响应内容
Variables ¶
View Source
var ErrProcessing = errors.New("order processing")
订单处理中错误
Functions ¶
Types ¶
type GetResultRes ¶
type GetResultRes struct { ResBody Content struct { OrderInfo struct { OrderId string `json:"orderId"` // 订单id FailType int `json:"failType"` // 订单失败类型,处理成功时响应0 Status int `json:"status"` // 订单流程状态 OriginalDuration int `json:"originalDuration"` // 上传设置音频时长,单位毫秒 RealDuration int `json:"realDuration"` // 实际处理音频时长,单位毫秒 ExpireTime int `json:"expireTime"` // 已完成订单删除时间戳,毫秒 } `json:"orderInfo"` // 转写订单信息 OrderResult string `json:"orderResult"` // 转写结果,json字符串 TaskEstimateTime int `json:"taskEstimateTime"` // 订单预估剩余耗时,单位毫秒 } `json:"content"` }
GetResultRes 获取处理结果响应体 响应代码为成功时,才能确定订单状态
type Lattice ¶
type Lattice struct {
Json1best Json1best `json:"json_1best"`
}
Lattice 单句转写结果
func (*Lattice) UnmarshalJSON ¶
UnmarshalJSON json解码 json_1best 响应字段是json字符串,将其直接解码为对象
type LfAsr ¶
type LfAsr struct { Appid string `json:"appid" env:"XFYUN_APP_ID"` LfAsrSecret string `json:"lfAsrSecret" env:"XFYUN_LF_ASR_SECRET"` // 语音转写密钥 }
func (LfAsr) GetResult ¶
func (a LfAsr) GetResult(orderId string) (*GetResultRes, error)
GetResult 获取处理结果,处理完成后72小时可查 订单处理失败或处理中,会返回错误 同一个订单最多获取100次结果
func (LfAsr) OrderResult ¶
func (a LfAsr) OrderResult(res *GetResultRes) (string, error)
OrderResult 解码转写结果,返回srt字幕
func (LfAsr) SpeechToText ¶
SpeechToText 上传音视频后,直接轮询获取语音转写结果,并转为srt字幕 name 是本地音视频文件路径,timeout 是轮询超时时间 官方音频时长与理论处理时间分钟: X<10 Y<3 10<=X<30 3<=Y<6 30<=X<60 6<=Y<10 60<=X 10<=Y<20
func (LfAsr) UploadCallback ¶
UploadCallback 订单完成时通知回调处理 get请求
type OrderResult ¶
type OrderResult struct { Lattice []Lattice `json:"lattice"` // 顺滑处理后的结果 Lattice2 []Lattice2 `json:"lattice2"` // 未顺滑处理的结果 }
OrderResult 转写结果 lattice 中 json_1best 是字符串 lattice2 中 json_1best 是对象
type St ¶
type St struct { Bg string `json:"bg"` // 单句开始时间毫秒数 Ed string `json:"ed"` // 单句结束时间毫秒数 Rl string `json:"rl"` Rt []Rt `json:"rt"` // 词语识别结果 }
St 单句转写结果
Click to show internal directories.
Click to hide internal directories.