synthesizer

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package synthesizer implements the Baidu ASR adapter for ling-base.

This adapter uses the Baidu REST short-audio recognition API. Audio bytes are accumulated locally and sent in a single POST request when SendEnd is invoked, which fits the ling-base Engine interface (non-streaming vendor).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaiduASR

type BaiduASR struct {
	Handler Handler
	// contains filtered or unexported fields
}

BaiduASR is the Baidu short-audio ASR engine.

func NewBaiduASR

func NewBaiduASR(opt BaiduASROption) *BaiduASR

NewBaiduASR builds a Baidu ASR engine from the supplied options.

func (*BaiduASR) Activity

func (b *BaiduASR) Activity() bool

Activity returns true if the engine is initialised for an active dialog.

func (*BaiduASR) ConnAndReceive

func (b *BaiduASR) ConnAndReceive(dialogID string) error

ConnAndReceive prepares the engine for a new dialog. For the REST-based flow this fetches (or refreshes) the access token and resets the audio buffer. No persistent connection is opened.

func (*BaiduASR) Init

func (b *BaiduASR) Init(tr base.ResultFunc, er base.ErrorFunc)

Init registers the result and error callbacks.

func (*BaiduASR) RestartClient

func (b *BaiduASR) RestartClient()

RestartClient resets the engine and re-initialises for the current dialog.

func (*BaiduASR) SendAudioBytes

func (b *BaiduASR) SendAudioBytes(data []byte) error

SendAudioBytes accumulates audio data into the local buffer. The actual recognition request is deferred until SendEnd is called.

func (*BaiduASR) SendEnd

func (b *BaiduASR) SendEnd() error

SendEnd flushes the accumulated audio to the Baidu REST API and parses the recognition result, dispatching it via the registered result callback.

func (*BaiduASR) StopConn

func (b *BaiduASR) StopConn() error

StopConn stops the engine and releases buffered audio.

func (*BaiduASR) Vendor

func (b *BaiduASR) Vendor() string

Vendor returns the vendor identifier string.

type BaiduASROption

type BaiduASROption struct {
	APIKey      string `json:"apiKey" yaml:"api_key"`
	SecretKey   string `json:"secretKey" yaml:"secret_key"`
	AppID       string `json:"appId" yaml:"app_id"`
	Format      string `json:"format" yaml:"format"`
	Rate        int    `json:"rate" yaml:"rate"`
	Channel     int    `json:"channel" yaml:"channel"`
	Cuid        string `json:"cuid" yaml:"cuid"`
	DevPid      int    `json:"devPid" yaml:"dev_pid"`
	ReqChanSize int    `json:"reqChanSize" yaml:"req_chan_size"`
}

BaiduASROption configures the Baidu ASR engine.

func NewBaiduASROption

func NewBaiduASROption(apiKey, secretKey string) BaiduASROption

NewBaiduASROption creates a default BaiduASROption.

func (*BaiduASROption) GetVendor

func (opt *BaiduASROption) GetVendor() base.Vendor

GetVendor returns the vendor identifier.

type BaiduASRResponse

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

BaiduASRResponse is the parsed recognition response from Baidu.

type Handler

type Handler interface{}

Handler is a generic media handler hook retained for compatibility with callers that previously relied on the LingEchoX media layer. It is not used by the REST-based recognition flow but kept so upstream code can attach session-scoped state if needed.

Jump to

Keyboard shortcuts

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