synthesizer

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package synthesizer implements the Xunfei (iFlytek) voice-clone TTS adapter for ling-base.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WSAudio

type WSAudio struct {
	Encoding   string `json:"encoding"`
	SampleRate int    `json:"sample_rate"`
}

WSAudio WebSocket音频参数

type WSHeader

type WSHeader struct {
	AppID  string `json:"app_id"`
	Status int    `json:"status"`
	ResID  string `json:"res_id"`
}

WSHeader WebSocket请求头

type WSParameter

type WSParameter struct {
	TTS WSTTS `json:"tts"`
}

WSParameter WebSocket参数

type WSPayload

type WSPayload struct {
	Text struct {
		Encoding string `json:"encoding"`
		Compress string `json:"compress"`
		Format   string `json:"format"`
		Status   int    `json:"status"`
		Seq      int    `json:"seq"`
		Text     string `json:"text"`
	} `json:"text"`
}

WSPayload WebSocket载荷

type WSRequest

type WSRequest struct {
	Header    WSHeader    `json:"header"`
	Parameter WSParameter `json:"parameter"`
	Payload   WSPayload   `json:"payload"`
}

WSRequest WebSocket请求结构

type WSTTS

type WSTTS struct {
	Vcn      string  `json:"vcn"`
	Volume   int     `json:"volume"`
	Rhy      int     `json:"rhy"`
	Pybuffer int     `json:"pybuffer"`
	Speed    int     `json:"speed"`
	Pitch    int     `json:"pitch"`
	Bgs      int     `json:"bgs"`
	Reg      int     `json:"reg"`
	Rdn      int     `json:"rdn"`
	Audio    WSAudio `json:"audio"`
}

WSTTS WebSocket TTS参数

type XunfeiService

type XunfeiService struct {
	// contains filtered or unexported fields
}

XunfeiService 讯飞TTS服务

func NewXunfeiService

func NewXunfeiService(opt XunfeiTTSConfig) *XunfeiService

NewXunfeiService 创建讯飞TTS服务

func (*XunfeiService) CacheKey

func (xs *XunfeiService) CacheKey(text string) string

CacheKey returns a unique cache key for the given text.

func (*XunfeiService) Close

func (xs *XunfeiService) Close() error

Close releases resources.

func (*XunfeiService) Format

func (xs *XunfeiService) Format() base.StreamFormat

Format returns the audio output format.

func (*XunfeiService) Provider

func (xs *XunfeiService) Provider() base.Provider

Provider returns the TTS provider identifier.

func (*XunfeiService) Synthesize

func (xs *XunfeiService) Synthesize(ctx context.Context, handler base.Handler, text string) error

Synthesize converts text to speech and delivers audio via the handler.

type XunfeiTTSConfig

type XunfeiTTSConfig struct {
	AppID         string `json:"app_id" yaml:"app_id" env:"XUNFEI_APP_ID"`
	APIKey        string `json:"api_key" yaml:"api_key" env:"XUNFEI_API_KEY"`
	APISecret     string `json:"api_secret" yaml:"api_secret" env:"XUNFEI_API_SECRET"`
	ResID         string `json:"res_id,omitempty" yaml:"res_id"`
	Vcn           string `json:"vcn,omitempty" yaml:"vcn"`
	SampleRate    int    `json:"sample_rate" yaml:"sample_rate" default:"24000"`
	Channels      int    `json:"channels" yaml:"channels" default:"1"`
	BitDepth      int    `json:"bit_depth" yaml:"bit_depth" default:"16"`
	Codec         string `json:"codec" yaml:"codec" default:"raw"`
	FrameDuration string `json:"frame_duration" yaml:"frame_duration" default:"20ms"`
	Timeout       int    `json:"timeout" yaml:"timeout" default:"30"`
}

XunfeiTTSConfig 讯飞TTS配置

func NewXunfeiTTSConfig

func NewXunfeiTTSConfig(appID, apiKey, apiSecret string) XunfeiTTSConfig

NewXunfeiTTSConfig 创建讯飞TTS配置

func (*XunfeiTTSConfig) GetProvider

func (c *XunfeiTTSConfig) GetProvider() base.Provider

GetProvider returns the TTS provider type

Jump to

Keyboard shortcuts

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