科大讯飞语音转写demo go语言版

上传了一个语音文件,识别效果。
在这里插入图片描述

package audio

import (
	"bytes"
	"crypto/hmac"
	"crypto/md5"
	"crypto/sha1"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"
	"strconv"
	"time"
)

const (
	lfasrHost    = "https://raasr.xfyun.cn/v2/api"
	apiUpload    = "/upload"
	apiGetResult = "/getResult"
)

type RequestApi struct {
   
	AppID          string
	SecretKey      string
	UploadFilePath string
	Timestamp      string
	Signa          string
}

// SpeechResult 代表整个识别结果的结构
type SpeechResult struct {
   
	Code     string        `json:"code"`
	Content  SpeechContent `json:"content"`
	DescInfo string        `json:"descInfo"`
}

// SpeechContent 代表 result 部分的结构
type SpeechContent struct {
   
	OrderInfo   OrderInfo `json:"orderInfo"`
	OrderResult string    `json:"orderResult"`
}

// OrderInfo 代表 orderInfo 部分的结构
type OrderInfo struct {
   
	ExpireTime       float64 `json:"expireTime"`
	FailType         int     `json:"failType"`
	OrderID          string  `json:"orderId"`
	OriginalDuration int     `json:"originalDuration"`
	RealDuration     int     `json:"realDuration"`
	Status           int     `json:"status"`
}

// SpeechResultData 代表 orderResult 中的数据结构
type SpeechResultData struct {
   
	Lattice  []LatticeItem  `json:"lattice"`
	Lattice2 []Lattice2Item `json:"lattice2"`
}

// LatticeItem 代表 lattice 部分的结构
type LatticeItem struct {
   
	Json1Best string `json:"json_1best"`
}

// Lattice2Item 代表 lattice2 部分的结构
type Lattice2Item struct {
   
	Lid       string       `json:"lid"`
	End       string       `json:"end"`
	Begin     string       `json:"begin"`
	Json1Best Lattice2Best `json:"json_1best"`
}

// Lattice2Best 代表 lattice2 中 json_1best 部分的结构
type Lattice2Best struct {
   
	St SpeechText `json:"st"`
}

// SpeechText 代表语音识别的详细文本结构
type SpeechText struct {
   
	Sc string     `json:"sc"`
	Pa string     `json:"pa"`
	Rt []SpeechRT `json:"rt"`
}

// SpeechRT 代表 rt 部分的结构
type SpeechRT struct {
   
	Ws []SpeechWS `json:"ws"`
}

// SpeechWS 代表 ws 部分的结构
type SpeechWS struct {
   
	Cw []SpeechCW `json:"cw"`
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值