voice

package
v0.0.0-...-4e5269b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

语音处理 利用百度RESTFul API 进行语音及文字的相互转换

Index

Constants

View Source
const (
	B = 1 << (10 * iota)
	KB
	MB
	GB
	TB
	PB
)
View Source
const ASR_URL = "http://vop.baidu.com/server_api"
View Source
const TTS_URL = "http://tsn.baidu.com/text2audio"

Variables

View Source
var (
	ErrTextTooLong = errors.New("the input string is too long")
)

Functions

This section is empty.

Types

type ASRParam

type ASRParam func(params *ASRParams)

func Channel

func Channel(c int) ASRParam

func Format

func Format(fmt string) ASRParam

func Language

func Language(lang string) ASRParam

func Rate

func Rate(rate int) ASRParam

type ASRParams

type ASRParams struct {
	Format   string `json:"format"`  //语音的格式,pcm 或者 wav 或者 amr。不区分大小写
	Rate     int    `json:"rate"`    //采样率,支持 8000 或者 16000
	Channel  int    `json:"channel"` //声道数,仅支持单声道,请填写固定值 1
	Cuid     string `json:"cuid"`    //用户唯一标识,用来区分用户,计算UV值。建议填写能区分用户的机器 MAC 地址或 IMEI 码,长度为60字符以内
	Token    string `json:"token"`   //开放平台获取到的开发者access_token
	Language string `json:"lan"`     //语种选择,默认中文(zh)。 中文=zh、粤语=ct、英文=en,不区分大小写
	Speech   string `json:"speech"`  //真实的语音数据 ,需要进行base64 编码。与len参数连一起使用
	Length   int    `json:"len"`     //原始语音长度,单位字节
}

语音识别参数

type ASRResponse

type ASRResponse struct {
	CorpusNo string   `json:"corpus_no"`
	ErrMsg   string   `json:"err_msg"`
	ErrNo    int      `json:"err_no"`
	Result   []string `json:"result"`
	SN       string   `json:"sn"`
}

语音识别响应信息

type TTSParam

type TTSParam func(params *TTSParams)

func Person

func Person(per int) TTSParam

func Pitch

func Pitch(pit int) TTSParam

func Speed

func Speed(spd int) TTSParam

func Volume

func Volume(vol int) TTSParam

type TTSParams

type TTSParams struct {
	Text       string `json:"tex"`
	Token      string `json:"tok"`
	Cuid       string `json:"cuid"`
	ClientType int    `json:"ctp"`
	Language   string `json:"lan"`
	Speed      int    `json:"spd"`
	Pitch      int    `json:"pit"`
	Volume     int    `json:"vol"`
	Person     int    `json:"per"`
}

type VoiceClient

type VoiceClient struct {
	*gosdk.Client
}

func NewVoiceClient

func NewVoiceClient(apiKey, apiSecret string) *VoiceClient

func (*VoiceClient) SpeechToText

func (vc *VoiceClient) SpeechToText(reader io.Reader, params ...ASRParam) ([]string, error)

SpeechToText 语音识别,将语音翻译成文字

func (*VoiceClient) TextToSpeech

func (vc *VoiceClient) TextToSpeech(txt string, params ...TTSParam) ([]byte, error)

TextToSpeech 语音合成,将文字转换为语音

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL