上传了一个语音文件,识别效果。
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"`