recognizer

package
v0.0.0-...-f17429d Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersionV1 = ProtocolVersion(0b0001)

	// Message Type
	MessageTypeClientFullRequest      = MessageType(0b0001)
	MessageTypeClientAudioOnlyRequest = MessageType(0b0010)
	MessageTypeServerFullResponse     = MessageType(0b1001)
	MessageTypeServerErrorResponse    = MessageType(0b1111)

	// Message Type Specific Flags
	FlagNoSequence      = MessageTypeSpecificFlags(0b0000) // no check sequence
	FlagPosSequence     = MessageTypeSpecificFlags(0b0001)
	FlagNegSequence     = MessageTypeSpecificFlags(0b0010)
	FlagNegWithSequence = MessageTypeSpecificFlags(0b0011)

	// Message Serialization
	SerializationNone = SerializationType(0b0000)
	SerializationJSON = SerializationType(0b0001)

	// Message Compression
	CompressionGZIP = CompressionType(0b0001)
)
View Source
const (
	SuccessCode = 1000

	ServerFullResponse  = MessageType(0b1001)
	ServerAck           = MessageType(0b1011)
	ServerErrorResponse = MessageType(0b1111)
)
View Source
const DefaultSampleRate = 16000

Variables

View Source
var DefaultAudioOnlyWsHeader = []byte{0x11, 0x20, 0x11, 0x00}
View Source
var DefaultFullClientWsHeader = []byte{0x11, 0x10, 0x11, 0x00}
View Source
var DefaultLastAudioWsHeader = []byte{0x11, 0x22, 0x11, 0x00}
View Source
var ErrClientClosed = errors.New("asr client closed")
View Source
var FussyMap = map[string]string{
	"s": "sh", "sh": "s",
	"c": "ch", "ch": "c",
	"z": "zh", "zh": "z",
	"l": "n", "n": "l",
	"f": "h", "h": "f",
	"r":  "l",
	"an": "ang", "ang": "an",
	"en": "eng", "eng": "en",
	"in": "ing", "ing": "in",
	"ian": "iang", "iang": "ian",
	"uan": "uang", "uang": "uan",
}

Functions

func ASRFilterSenderName

func ASRFilterSenderName(senderName, direction string, h media.MediaHandler) string

func AudioIntercept

func AudioIntercept() media.MediaHandlerFunc

func ConvertToWAV

func ConvertToWAV(audioPath string, sampleRate int) ([]byte, error)

ConvertToWAV converts an audio file to WAV format with the specified sample rate

func GenerateCorpusContext

func GenerateCorpusContext(hotwords []HotWord) string

func GzipCompress

func GzipCompress(input []byte) []byte

GzipCompress compresses input data using gzip

func GzipDecompress

func GzipDecompress(input []byte) []byte

GzipDecompress decompresses input data using gzip

func IsWAVFile

func IsWAVFile(data []byte) bool

IsWAVFile checks if the byte array is a valid WAV file

func NewAudioOnlyRequest

func NewAudioOnlyRequest(seq int, segment []byte) []byte

func NewAuthHeader

func NewAuthHeader(auth AuthConfig) http.Header

func NewFullClientRequest

func NewFullClientRequest(config *Config) []byte

NewFullClientRequest creates a full client request payload

func ReadWAVInfo

func ReadWAVInfo(data []byte) (int, int, int, int, []byte, error)

ReadWAVInfo reads WAV file info and returns channels, sample width, sample rate, packet count, data, and error

func WithAwsASR

func WithAwsASR(opt AwsASROption) media.MediaHandlerFunc

func WithBaiduASR

func WithBaiduASR(opt BaiduASROption) media.MediaHandlerFunc

func WithDeepgramASR

func WithDeepgramASR(opt DeepgramASROption) media.MediaHandlerFunc

func WithQCloudASR

func WithQCloudASR(opt QCloudASROption) media.MediaHandlerFunc

func WithVoiceapiASR

func WithVoiceapiASR(opt VoiceapiASROption) media.MediaHandlerFunc

func WithVolcengineASR

func WithVolcengineASR(opt VolcengineOption) media.MediaHandlerFunc

func WithWhisperASR

func WithWhisperASR(opt WhisperASROption) media.MediaHandlerFunc

Types

type AsrCorrector

type AsrCorrector struct {
	ReplaceWords map[string]string
	FuzzyWords   map[string]string
	// contains filtered or unexported fields
}

func NewAsrCorrector

func NewAsrCorrector(opt AsrCorrectorOption) *AsrCorrector

func (*AsrCorrector) Correct

func (ac *AsrCorrector) Correct(text string) string

func (*AsrCorrector) SegmentWords

func (ac *AsrCorrector) SegmentWords(s string) []string

type AsrCorrectorOption

type AsrCorrectorOption struct {
	ReplaceWords map[string]string `json:"replaceWords"`
	FuzzyWords   map[string]string `json:"fuzzyWords"`
}

type AudioConfig

type AudioConfig struct {
	Format  string `json:"format" yaml:"format" default:"pcm"`
	Codec   string `json:"codec" yaml:"codec" default:"raw"`
	Rate    int    `json:"rate" yaml:"rate" default:"16000"`
	Bits    int    `json:"bits" yaml:"bits" default:"16"`
	Channel int    `json:"channel" yaml:"channel" default:"1"`
}

AudioConfig represents audio format configuration

type AudioFrame

type AudioFrame struct {
	IsEnd bool
	Data  []byte
}

type AudioMeta

type AudioMeta struct {
	Format  string `json:"format,omitempty"`
	Codec   string `json:"codec,omitempty"`
	Rate    int    `json:"rate,omitempty"`
	Bits    int    `json:"bits,omitempty"`
	Channel int    `json:"channel,omitempty"`
}

type AuthConfig

type AuthConfig struct {
	ResourceId string `json:"resource_id" yaml:"resource_id"`
	AccessKey  string `json:"access_key" yaml:"access_key"`
	AppKey     string `json:"app_key" yaml:"app_key"`
}

AuthConfig represents authentication configuration

type AwsASR

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

type AwsASROption

type AwsASROption struct {
	AppID       string              `json:"appId" yaml:"app_id"`
	Region      string              `json:"region" yaml:"region"`
	Encoding    types.MediaEncoding `json:"encoding" yaml:"encoding"`
	SampleRate  int32               `json:"sampleRate" yaml:"sample_rate"`
	ReqChanSize int                 `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
}

func NewAwsASROption

func NewAwsASROption(appId, region string, language string) AwsASROption

func (*AwsASROption) GetVendor

func (opt *AwsASROption) GetVendor() Vendor

type BaiduASR

type BaiduASR struct {
	Sentence string
	// contains filtered or unexported fields
}

type BaiduASRBeginParam

type BaiduASRBeginParam struct {
	Type string `json:"type"`
	Data Data   `json:"data"`
}

func NewBeginParam

func NewBeginParam(opt BaiduASROption) BaiduASRBeginParam

type BaiduASROption

type BaiduASROption struct {
	Url         string `json:"url" yaml:"url" default:"wss://vop.baidu.com/realtime_asr"`
	AppID       int    `json:"appId" yaml:"app_id"`
	AppKey      string `json:"appKey" yaml:"app_key"`
	DevPid      int    `json:"devPid" yaml:"dev_pid"`
	LmId        int    `json:"lmId" yaml:"lm_id"`
	CuId        string `json:"cuId" yaml:"cu_id"`
	Format      string `json:"format" yaml:"format"`
	Sample      int    `json:"sample" yaml:"sample"`
	ReqChanSize int    `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
}

func NewBaiduASROption

func NewBaiduASROption(appId int, appKey string, devPid int, format string, sample int) BaiduASROption

func (*BaiduASROption) GetVendor

func (opt *BaiduASROption) GetVendor() Vendor

type BaiduASRWSResponse

type BaiduASRWSResponse struct {
	ErrNo     int    `json:"err_no"`
	ErrMsg    string `json:"err_msg"`
	Type      string `json:"type"`
	Result    string `json:"result"`
	StartTime int    `json:"start_time"`
	EndTime   int    `json:"end_time"`
	LogId     int    `json:"log_id"`
	Sn        string `json:"sn"`
}

type BufferConfig

type BufferConfig struct {
	SegmentDurationMs int `json:"segment_duration_ms" yaml:"segment_duration_ms" default:"200"`
	MaxBufferSize     int `json:"max_buffer_size" yaml:"max_buffer_size"`
}

BufferConfig represents buffer configuration

type Client

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

func NewClient

func NewClient(config *Config) *Client

func (*Client) Close

func (c *Client) Close()

Close closes the connection

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect establishes WebSocket connection and authenticates

func (*Client) GetTraceID

func (c *Client) GetTraceID() string

GetTraceID returns the trace ID from the connection

func (*Client) IsClosed

func (c *Client) IsClosed() bool

IsClosed returns true if the client is closed

func (*Client) ReceiveResult

func (c *Client) ReceiveResult() (*Response, error)

func (*Client) SendAudioFrame

func (c *Client) SendAudioFrame(frame *AudioFrame) error

func (*Client) SetErrorCallback

func (c *Client) SetErrorCallback(callback func(error))

SetErrorCallback sets the error callback function

func (*Client) SetTimeouts

func (c *Client) SetTimeouts(writeTimeout, readTimeout time.Duration)

SetTimeouts sets the timeouts for write and read operations

type CompressionType

type CompressionType byte

type Config

type Config struct {
	// Connection settings
	URL string `json:"url" yaml:"url"`

	// Auth settings
	Auth AuthConfig `json:"auth" yaml:"auth"`

	// User metadata
	User UserConfig `json:"user" yaml:"user"`

	// Audio format settings
	Audio AudioConfig `json:"audio" yaml:"audio"`

	// Request settings
	Request RequestConfig `json:"request" yaml:"request"`

	// Buffer settings
	Buffer BufferConfig `json:"buffer" yaml:"buffer"`
}

Config represents the configuration for SAUC ASR client

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration

func (*Config) CalculateBufferSize

func (c *Config) CalculateBufferSize() int

CalculateBufferSize calculates the buffer size based on audio format and segment duration

func (*Config) WithAudio

func (c *Config) WithAudio(audio AudioConfig) *Config

WithAudio sets the audio configuration

func (*Config) WithAuth

func (c *Config) WithAuth(auth AuthConfig) *Config

WithAuth sets the auth configuration

func (*Config) WithBuffer

func (c *Config) WithBuffer(buffer BufferConfig) *Config

WithBuffer sets the buffer configuration

func (*Config) WithRequest

func (c *Config) WithRequest(request RequestConfig) *Config

WithRequest sets the request configuration

func (*Config) WithURL

func (c *Config) WithURL(url string) *Config

WithURL sets the URL for the ASR service

func (*Config) WithUser

func (c *Config) WithUser(user UserConfig) *Config

WithUser sets the user configuration

type ConfigReader

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

ConfigReader 配置读取器 - 简化配置读取逻辑

func NewConfigReader

func NewConfigReader(config map[string]interface{}) *ConfigReader

NewConfigReader 创建配置读取器

func (*ConfigReader) Int

func (r *ConfigReader) Int(keys ...interface{}) int

Int 获取整数值,支持多个键名和默认值 用法: Int("key1", "key2", 100)

func (*ConfigReader) String

func (r *ConfigReader) String(keysAndDefault ...string) string

String 获取字符串值,支持多个键名和默认值 用法: String("key1", "key2", "default_value")

type CorpusConfig

type CorpusConfig struct {
	BoostingTableName string `json:"boosting_table_name" yaml:"boosting_table_name"`
	CorrectTableName  string `json:"correct_table_name" yaml:"correct_table_name"`
	Context           string `json:"context" yaml:"context"`
}

CorpusConfig represents corpus configuration

type CorpusMeta

type CorpusMeta struct {
	BoostingTableName string `json:"boosting_table_name,omitempty"`
	CorrectTableName  string `json:"correct_table_name,omitempty"`
	Context           string `json:"context,omitempty"`
}

type Data

type Data struct {
	AppId  int    `json:"appid"`
	AppKey string `json:"appkey"`
	DevPid int    `json:"dev_pid"`
	LmId   int    `json:"lm_id"`
	CuId   string `json:"cuid"`
	Format string `json:"format"`
	Sample int    `json:"sample"`
}

type DeepgramASR

type DeepgramASR struct {
	Sentence string
	EndTime  uint32
	// contains filtered or unexported fields
}

func (*DeepgramASR) Close

func (*DeepgramASR) Error

func (*DeepgramASR) Message

func (dg *DeepgramASR) Message(mr *interfacesv1.MessageResponse) error

func (*DeepgramASR) Metadata

func (dg *DeepgramASR) Metadata(md *interfacesv1.MetadataResponse) error

func (*DeepgramASR) Open

func (*DeepgramASR) SpeechStarted

func (dg *DeepgramASR) SpeechStarted(ssr *interfacesv1.SpeechStartedResponse) error

func (*DeepgramASR) UnhandledEvent

func (dg *DeepgramASR) UnhandledEvent(byData []byte) error

func (*DeepgramASR) UtteranceEnd

func (dg *DeepgramASR) UtteranceEnd(ur *interfacesv1.UtteranceEndResponse) error

type DeepgramASROption

type DeepgramASROption struct {
	ApiKey            string `json:"apiKey" yaml:"api_key" env:"DEEPGRAM_API_KEY"`
	Model             string `json:"model" yaml:"model" default:"nova-2"`
	Language          string `json:"language" yaml:"language" default:"en-US"`
	SampleRate        int    `json:"sampleRate" yaml:"sample_rate" default:"16000"`
	Channels          int    `json:"channels" yaml:"channels" default:"1"`
	Encoding          string `json:"encoding" yaml:"encoding" default:"linear16"`
	ReqChanSize       int    `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
	KeepAliveDuration string `json:"keepAlineDuration" yaml:"keep_aline_duration" default:"3s"`
}

func NewDeepgramASROption

func NewDeepgramASROption(apiKey string, model string, language string) DeepgramASROption

func (*DeepgramASROption) GetVendor

func (opt *DeepgramASROption) GetVendor() Vendor

type DefaultTranscriberFactory

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

DefaultTranscriberFactory 默认工厂实现

func GetGlobalFactory

func GetGlobalFactory() *DefaultTranscriberFactory

GetGlobalFactory 获取全局工厂实例(单例模式)

func NewTranscriberFactory

func NewTranscriberFactory() *DefaultTranscriberFactory

NewTranscriberFactory 创建新的工厂实例

func (*DefaultTranscriberFactory) CreateTranscriber

func (f *DefaultTranscriberFactory) CreateTranscriber(config TranscriberConfig) (TranscribeService, error)

CreateTranscriber 创建 TranscribeService

func (*DefaultTranscriberFactory) GetSupportedVendors

func (f *DefaultTranscriberFactory) GetSupportedVendors() []Vendor

GetSupportedVendors 获取支持的供应商列表

func (*DefaultTranscriberFactory) IsVendorSupported

func (f *DefaultTranscriberFactory) IsVendorSupported(vendor Vendor) bool

IsVendorSupported 检查供应商是否支持

func (*DefaultTranscriberFactory) RegisterCreator

func (f *DefaultTranscriberFactory) RegisterCreator(vendor Vendor, creator func(TranscriberConfig) (TranscribeService, error))

RegisterCreator 注册创建函数

type Event

type Event struct {
	Header  FunHeader  `json:"header"`
	Payload FunPayload `json:"payload"`
}

type FunASRCallback

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

func NewFunASR

func NewFunASR(opt FunASROption) FunASRCallback

func (*FunASRCallback) Activity

func (fun *FunASRCallback) Activity() bool

func (*FunASRCallback) ConnAndReceive

func (fun *FunASRCallback) ConnAndReceive(dialogID string) error

func (*FunASRCallback) Init

func (fun *FunASRCallback) Init(tr TranscribeResult, er ProcessError)

func (*FunASRCallback) RestartClient

func (fun *FunASRCallback) RestartClient()

func (*FunASRCallback) SendAudioBytes

func (fun *FunASRCallback) SendAudioBytes(data []byte) error

func (*FunASRCallback) SendEnd

func (fun *FunASRCallback) SendEnd() error

func (*FunASRCallback) StopConn

func (fun *FunASRCallback) StopConn() error

func (*FunASRCallback) Vendor

func (fun *FunASRCallback) Vendor() string

type FunASRClient

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

type FunASRMessage

type FunASRMessage struct {
	Mode    string `json:"mode"`
	Text    string `json:"text"`
	IsFinal bool   `json:"is_final"`
}

type FunASROption

type FunASROption struct {
	Url                  string `json:"url" yaml:"url" env:"FUNASR_URL"`
	Mode                 string `json:"mode" yaml:"mode"`
	ChunkSize            []int  `json:"chunkSize" yaml:"chunk_size"`
	ChunkInterval        int    `json:"chunkInterval" yaml:"chunk_interval"`
	EncoderChunkLookBack int    `json:"encoderChunkLookBack" yaml:"encoder_chunk_look_back"`
	DecoderChunkLookBack int    `json:"decoderChunkLookBack" yaml:"decoder_chunk_look_back"`
	AudioFs              int    `json:"audioFs" yaml:"audio_fs"`
	WavName              string `json:"wavName" yaml:"wav_name"`
	WavFormat            string `json:"wavFormat" yaml:"wav_format"`
	IsSpeaking           bool   `json:"isSpeaking" yaml:"is_speaking"`
	Hotwords             string `json:"hotwords" yaml:"hotwords"`
	Itn                  bool   `json:"itn" yaml:"itn"`
	ReqChanSize          int    `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
}

func NewFunASROption

func NewFunASROption(url string) FunASROption

func (*FunASROption) GetVendor

func (opt *FunASROption) GetVendor() Vendor

type FunASRRequestOption

type FunASRRequestOption struct {
	Mode                 string `json:"mode"`
	ChunkSize            []int  `json:"chunk_size"`
	ChunkInterval        int    `json:"chunk_interval"`
	EncoderChunkLookBack int    `json:"encoder_chunk_look_back"`
	DecoderChunkLookBack int    `json:"decoder_chunk_look_back"`
	AudioFs              int    `json:"audio_fs"`
	WavName              string `json:"wav_name"`
	WavFormat            string `json:"wav_format"`
	IsSpeaking           bool   `json:"is_speaking"`
	Hotwords             string `json:"hotwords"`
	Itn                  bool   `json:"itn"`
}

func NewFunASRRequestOption

func NewFunASRRequestOption(opt FunASROption) FunASRRequestOption

type FunAsrRealtime

type FunAsrRealtime struct {
	Handler media.MediaHandler
	// contains filtered or unexported fields
}

func NewFunAsrRealtime

func NewFunAsrRealtime(opt FunAsrRealtimeOption) FunAsrRealtime

func (*FunAsrRealtime) Activity

func (fun *FunAsrRealtime) Activity() bool

func (*FunAsrRealtime) ConnAndReceive

func (fun *FunAsrRealtime) ConnAndReceive(dialogID string) error

func (*FunAsrRealtime) Init

func (fun *FunAsrRealtime) Init(tr TranscribeResult, er ProcessError)

func (*FunAsrRealtime) RestartClient

func (fun *FunAsrRealtime) RestartClient()

func (*FunAsrRealtime) SendAudioBytes

func (fun *FunAsrRealtime) SendAudioBytes(data []byte) error

func (*FunAsrRealtime) SendEnd

func (fun *FunAsrRealtime) SendEnd() error

func (*FunAsrRealtime) StopConn

func (fun *FunAsrRealtime) StopConn() error

func (*FunAsrRealtime) Vendor

func (fun *FunAsrRealtime) Vendor() string

type FunAsrRealtimeClient

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

type FunAsrRealtimeOption

type FunAsrRealtimeOption struct {
	Url                      string `json:"url" yaml:"url" env:"FUNASR_URL" default:"wss://dashscope.aliyuncs.com/api-ws/v1/inference"`
	ApiKey                   string `json:"apiKey" yaml:"api_key" env:"DASHSCOPE_API_KEY"`
	Model                    string `json:"model" yaml:"model" default:"fun-asr-realtime"`
	SampleRate               int    `json:"sampleRate" yaml:"sample_rate" default:"16000"`
	Format                   string `json:"format" yaml:"format" default:"pcm"`
	LanguageHints            string `json:"languageHints" yaml:"language_hints" default:"zh"`
	EnableWords              bool   `json:"enableWords" yaml:"enable_words" default:"false"`
	EnableITN                bool   `json:"enableITN" yaml:"enable_itn" default:"false"`
	MaxSentenceSilence       uint   `json:"maxSentenceSilence" yaml:"max_sentence_silence" default:"1300"` // ms
	Heartbeat                bool   `json:"heartbeat" yaml:"heartbeat" default:"false"`
	DisfluencyRemovalEnabled bool   `json:"disfluencyRemovalEnabled" yaml:"disfluency_removal_enabled" default:"false"`
}

func (*FunAsrRealtimeOption) GetVendor

func (opt *FunAsrRealtimeOption) GetVendor() Vendor

type FunHeader

type FunHeader struct {
	Action       string                 `json:"action"`
	TaskID       string                 `json:"task_id"`
	Streaming    string                 `json:"streaming"`
	Event        string                 `json:"event"`
	ErrorCode    string                 `json:"error_code,omitempty"`
	ErrorMessage string                 `json:"error_message,omitempty"`
	Attributes   map[string]interface{} `json:"attributes"`
}

type FunPayload

type FunPayload struct {
	TaskGroup  string `json:"task_group"`
	Task       string `json:"task"`
	Function   string `json:"function"`
	Model      string `json:"model"`
	Parameters Params `json:"parameters"`
	Input      Input  `json:"input"`
	Output     Output `json:"output,omitempty"`
	Usage      *struct {
		Duration int `json:"duration"`
	} `json:"usage,omitempty"`
}

type GladiaASR

type GladiaASR struct {
	Sentence string
	// contains filtered or unexported fields
}

func NewGladiaASR

func NewGladiaASR(opt GladiaASROption) GladiaASR

func (*GladiaASR) Activity

func (gla *GladiaASR) Activity() bool

func (*GladiaASR) ConnAndReceive

func (gla *GladiaASR) ConnAndReceive(dialogID string) error

func (*GladiaASR) Init

func (gla *GladiaASR) Init(tr TranscribeResult, er ProcessError)

func (*GladiaASR) RestartClient

func (gla *GladiaASR) RestartClient()

func (*GladiaASR) SendAudioBytes

func (gla *GladiaASR) SendAudioBytes(data []byte) error

func (*GladiaASR) SendEnd

func (gla *GladiaASR) SendEnd() error

func (*GladiaASR) StopConn

func (gla *GladiaASR) StopConn() error

func (*GladiaASR) Vendor

func (gla *GladiaASR) Vendor() string

type GladiaASROption

type GladiaASROption struct {
	Url         string `json:"url" yaml:"url" default:"wss://api.gladia.io/audio/text/audio-transcription"`
	ApiKey      string `json:"apiKey" yaml:"api_key"`
	Encoding    string `json:"encoding" yaml:"encoding" default:"WAV/PCM"`
	ReqChanSize int    `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
}

func NewGladiaASROption

func NewGladiaASROption(apiKey string, encoding string) GladiaASROption

func (*GladiaASROption) GetVendor

func (opt *GladiaASROption) GetVendor() Vendor

type GladiaUtterance

type GladiaUtterance struct {
	Transcription string  `json:"transcription"`
	TimeBegin     float64 `json:"time_begin"`
	TimeEnd       float64 `json:"time_end"`
	Language      string  `json:"language"`
	Confidence    float64 `json:"confidence"`
	Stable        bool    `json:"stable"`
	ID            int     `json:"id"`
}

type GoogleASR

type GoogleASR struct {
	Sentence string
	// contains filtered or unexported fields
}

func NewGoogleASR

func NewGoogleASR(opt GoogleASROption) GoogleASR

func (*GoogleASR) Activity

func (google *GoogleASR) Activity() bool

func (*GoogleASR) ConnAndReceive

func (google *GoogleASR) ConnAndReceive(dialogID string) error

func (*GoogleASR) Init

func (google *GoogleASR) Init(tr TranscribeResult, er ProcessError)

func (*GoogleASR) RestartClient

func (google *GoogleASR) RestartClient()

func (*GoogleASR) SendAudioBytes

func (google *GoogleASR) SendAudioBytes(data []byte) error

func (*GoogleASR) SendEnd

func (google *GoogleASR) SendEnd() error

func (*GoogleASR) StopConn

func (google *GoogleASR) StopConn() error

func (*GoogleASR) Vendor

func (google *GoogleASR) Vendor() string

type GoogleASROption

type GoogleASROption struct {
	Encoding        speechpb.RecognitionConfig_AudioEncoding `json:"encoding" yaml:"encoding"`
	SampleRateHertz int32                                    `json:"sampleRateHertz" yaml:"sample_rate_hertz"`
	LanguageCode    string                                   `json:"languageCode" yaml:"language_code"`
	ReqChainSize    int                                      `json:"reqChainSize" yaml:"req_chain_size" default:"128"`
}

func NewGoogleASROption

func NewGoogleASROption(encoding speechpb.RecognitionConfig_AudioEncoding, sampleRateHertz int32, languageCode string) GoogleASROption

func (*GoogleASROption) GetVendor

func (opt *GoogleASROption) GetVendor() Vendor

type HotWord

type HotWord struct {
	Word   string `json:"word"`
	Weight int    `json:"weight"`
}

type Input

type Input struct {
}

type LocalASRConfig

type LocalASRConfig struct {
	Provider     LocalASRProvider `json:"provider"`     // ASR提供商
	ModelPath    string           `json:"modelPath"`    // 模型文件路径
	Language     string           `json:"language"`     // 语言代码
	SampleRate   int              `json:"sampleRate"`   // 采样率
	Channels     int              `json:"channels"`     // 声道数
	BitDepth     int              `json:"bitDepth"`     // 位深度
	BufferSize   int              `json:"bufferSize"`   // 缓冲区大小(毫秒)
	EnableVAD    bool             `json:"enableVAD"`    // 是否启用VAD
	VADThreshold float32          `json:"vadThreshold"` // VAD阈值
	Command      string           `json:"command"`      // 外部命令(用于 local_cmd 模式)
}

LocalASRConfig 本地ASR配置

func NewLocalASRConfig

func NewLocalASRConfig(provider LocalASRProvider, modelPath string) *LocalASRConfig

NewLocalASRConfig 创建默认本地ASR配置

func (*LocalASRConfig) GetVendor

func (opt *LocalASRConfig) GetVendor() Vendor

type LocalASRProvider

type LocalASRProvider string

LocalASRProvider 本地ASR提供商类型

const (
	LocalASRProviderWhisperCpp LocalASRProvider = "whisper_cpp"
	LocalASRProviderLocal      LocalASRProvider = "local_cmd"
)

type LocalASRService

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

LocalASRService 本地ASR服务

func NewLocalASRService

func NewLocalASRService(config *LocalASRConfig) (*LocalASRService, error)

NewLocalASRService 创建本地ASR服务

func (*LocalASRService) Activity

func (s *LocalASRService) Activity() bool

Activity 检查活动状态

func (*LocalASRService) Close

func (s *LocalASRService) Close() error

Close 关闭服务

func (*LocalASRService) ConnAndReceive

func (s *LocalASRService) ConnAndReceive(dialogId string) error

ConnAndReceive 连接并接收

func (*LocalASRService) Init

Init 初始化服务

func (*LocalASRService) RestartClient

func (s *LocalASRService) RestartClient()

RestartClient 重启客户端

func (*LocalASRService) SendAudioBytes

func (s *LocalASRService) SendAudioBytes(data []byte) error

SendAudioBytes 发送音频数据

func (*LocalASRService) SendEnd

func (s *LocalASRService) SendEnd() error

SendEnd 发送结束信号

func (*LocalASRService) StopConn

func (s *LocalASRService) StopConn() error

StopConn 停止连接

func (*LocalASRService) Vendor

func (s *LocalASRService) Vendor() string

Vendor 返回供应商名称

type MessageType

type MessageType byte

type MessageTypeSpecificFlags

type MessageTypeSpecificFlags byte

type Output

type Output struct {
	Sentence struct {
		SentenceEnd bool   `json:"sentence_end"`
		BeginTime   int64  `json:"begin_time"`
		EndTime     *int64 `json:"end_time"`
		Text        string `json:"text"`
		Words       []struct {
			BeginTime   int64  `json:"begin_time"`
			EndTime     *int64 `json:"end_time"`
			Text        string `json:"text"`
			Punctuation string `json:"punctuation"`
		} `json:"words"`
	} `json:"sentence"`
}

type Params

type Params struct {
	Format                   string   `json:"format"`
	SampleRate               int      `json:"sample_rate"`
	VocabularyID             string   `json:"vocabulary_id"`
	DisfluencyRemovalEnabled bool     `json:"disfluency_removal_enabled"`
	LanguageHints            []string `json:"language_hints"`
	// fun asr special
	MaxSentenceSilence uint `json:"maxSentenceSilence"` // ms
	Heartbeat          bool `json:"heartbeat"`
}

type ProcessError

type ProcessError func(err error, isFatal bool)

type ProtocolVersion

type ProtocolVersion byte

type QCloudASR

type QCloudASR struct {
	Handler media.MediaHandler
	// contains filtered or unexported fields
}

func NewQcloudASR

func NewQcloudASR(opt QCloudASROption) *QCloudASR

func (*QCloudASR) Activity

func (asq *QCloudASR) Activity() bool

func (*QCloudASR) ConnAndReceive

func (asq *QCloudASR) ConnAndReceive(dialogID string) error

func (*QCloudASR) Init

func (asq *QCloudASR) Init(tr TranscribeResult, er ProcessError)

func (*QCloudASR) OnFail

func (asq *QCloudASR) OnFail(response *asr.SpeechRecognitionResponse, err error)

OnFail implementation of SpeechRecognitionListener

func (*QCloudASR) OnRecognitionComplete

func (asq *QCloudASR) OnRecognitionComplete(response *asr.SpeechRecognitionResponse)

OnRecognitionComplete implementation of SpeechRecognitionListener

func (*QCloudASR) OnRecognitionResultChange

func (asq *QCloudASR) OnRecognitionResultChange(response *asr.SpeechRecognitionResponse)

OnRecognitionResultChange implementation of SpeechRecognitionListener

func (*QCloudASR) OnRecognitionStart

func (asq *QCloudASR) OnRecognitionStart(response *asr.SpeechRecognitionResponse)

OnRecognitionStart implementation of SpeechRecognitionListener

func (*QCloudASR) OnSentenceBegin

func (asq *QCloudASR) OnSentenceBegin(response *asr.SpeechRecognitionResponse)

OnSentenceBegin implementation of SpeechRecognitionListener

func (*QCloudASR) OnSentenceEnd

func (asq *QCloudASR) OnSentenceEnd(response *asr.SpeechRecognitionResponse)

OnSentenceEnd implementation of SpeechRecognitionListener

func (*QCloudASR) RestartClient

func (asq *QCloudASR) RestartClient()

func (*QCloudASR) SendAudioBytes

func (asq *QCloudASR) SendAudioBytes(data []byte) error

func (*QCloudASR) SendEnd

func (asq *QCloudASR) SendEnd() error

func (*QCloudASR) StopConn

func (asq *QCloudASR) StopConn() error

func (*QCloudASR) Vendor

func (asq *QCloudASR) Vendor() string

type QCloudASROption

type QCloudASROption struct {
	AppID       string    `json:"appId" yaml:"app_id" env:"QCLOUD_APP_ID"`
	SecretID    string    `json:"secretId" yaml:"secret_id" env:"QCLOUD_SECRET_ID"`
	SecretKey   string    `json:"secret" yaml:"secret" env:"QCLOUD_SECRET"`
	Format      int       `json:"format" yaml:"format" default:"1"`
	ModelType   string    `json:"modelType" yaml:"model_type" env:"QCLOUD_MODEL_TYPE" default:"16k_zh"`
	ReqChanSize int       `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
	HotWords    []HotWord `json:"hotWords" yaml:"hot_words"`
}

func NewQcloudASROption

func NewQcloudASROption(appId string, secretId string, secretKey string) QCloudASROption

func (*QCloudASROption) GetVendor

func (opt *QCloudASROption) GetVendor() Vendor

func (QCloudASROption) String

func (opt QCloudASROption) String() string

type Recognizer

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

func NewRecognizer

func NewRecognizer(config *Config) *Recognizer

func (*Recognizer) GetTraceID

func (r *Recognizer) GetTraceID() string

func (*Recognizer) SendAudioFrame

func (r *Recognizer) SendAudioFrame(frame []byte, end bool) error

func (*Recognizer) SetErrorCallback

func (r *Recognizer) SetErrorCallback(callback func(error))

SetErrorCallback sets the callback function for handling errors

func (*Recognizer) SetResultCallback

func (r *Recognizer) SetResultCallback(callback ResultCallback)

SetResultCallback sets the callback function for handling recognition results

func (*Recognizer) Start

func (r *Recognizer) Start() error

func (*Recognizer) Stop

func (r *Recognizer) Stop()

type RequestConfig

type RequestConfig struct {
	ModelName       string       `json:"model_name" yaml:"model_name" default:"bigmodel"`
	EnableITN       bool         `json:"enable_itn" yaml:"enable_itn" default:"true"`
	EnablePUNC      bool         `json:"enable_punc" yaml:"enable_punc" default:"true"`
	EnableDDC       bool         `json:"enable_ddc" yaml:"enable_ddc" default:"true"`
	ShowUtterances  bool         `json:"show_utterances" yaml:"show_utterances" default:"true"`
	EnableNonstream bool         `json:"enable_nonstream" yaml:"enable_nonstream" default:"false"`
	Corpus          CorpusConfig `json:"corpus" yaml:"corpus"`
}

RequestConfig represents request configuration

type RequestHeader

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

func DefaultHeader

func DefaultHeader() *RequestHeader

func (*RequestHeader) WithCompressionType

func (h *RequestHeader) WithCompressionType(compressionType CompressionType) *RequestHeader

func (*RequestHeader) WithMessageType

func (h *RequestHeader) WithMessageType(messageType MessageType) *RequestHeader

func (*RequestHeader) WithMessageTypeSpecificFlags

func (h *RequestHeader) WithMessageTypeSpecificFlags(messageTypeSpecificFlags MessageTypeSpecificFlags) *RequestHeader

func (*RequestHeader) WithReservedData

func (h *RequestHeader) WithReservedData(reservedData []byte) *RequestHeader

func (*RequestHeader) WithSerializationType

func (h *RequestHeader) WithSerializationType(serializationType SerializationType) *RequestHeader

type RequestMeta

type RequestMeta struct {
	ModelName       string     `json:"model_name,omitempty"`
	EnableITN       bool       `json:"enable_itn,omitempty"`
	EnablePUNC      bool       `json:"enable_punc,omitempty"`
	EnableDDC       bool       `json:"enable_ddc,omitempty"`
	ShowUtterances  bool       `json:"show_utterances"`
	EnableNonstream bool       `json:"enable_nonstream"`
	Corpus          CorpusMeta `json:"corpus,omitempty"`
}

type RequestPayload

type RequestPayload struct {
	User    UserMeta    `json:"user"`
	Audio   AudioMeta   `json:"audio"`
	Request RequestMeta `json:"request"`
}

type Response

type Response struct {
	Code            int              `json:"code"`
	Event           int              `json:"event"`
	IsLastPackage   bool             `json:"is_last_package"`
	PayloadSequence int32            `json:"payload_sequence"`
	PayloadSize     int              `json:"payload_size"`
	PayloadMsg      *ResponsePayload `json:"payload_msg"`
	Err             error
}

func ParseResponse

func ParseResponse(msg []byte) *Response

ParseResponse parses the response message

type ResponsePayload

type ResponsePayload struct {
	AudioInfo struct {
		Duration int `json:"duration"`
	} `json:"audio_info"`
	Result struct {
		Text       string `json:"text"`
		Utterances []struct {
			Definite  bool   `json:"definite"`
			EndTime   int    `json:"end_time"`
			StartTime int    `json:"start_time"`
			Text      string `json:"text"`
			Words     []struct {
				EndTime   int    `json:"end_time"`
				StartTime int    `json:"start_time"`
				Text      string `json:"text"`
			} `json:"words"`
		} `json:"utterances,omitempty"`
	} `json:"result"`
	Error string `json:"error,omitempty"`
}

type Result

type Result struct {
	Text      string    `json:"text"`
	IsFinal   bool      `json:"is_final"`
	Timestamp time.Time `json:"timestamp"`
	Error     error     `json:"error,omitempty"`
}

type ResultCallback

type ResultCallback func(*Result)

ResultCallback defines the callback interface for handling recognition results

type RingBuffer

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

func NewRingBuffer

func NewRingBuffer(size int) *RingBuffer

func (*RingBuffer) Read

func (r *RingBuffer) Read(n int) []byte

func (*RingBuffer) Write

func (r *RingBuffer) Write(data []byte) int

type SerializationType

type SerializationType byte

type TranscribeOneShot

type TranscribeOneShot struct {
	Padding int
	// contains filtered or unexported fields
}

type TranscribeOption

type TranscribeOption struct {
	Direction    string             `json:"direction,omitempty"`
	AsrOptions   map[string]any     `json:"asrOptions,omitempty"`
	FuzzyOptions AsrCorrectorOption `json:"fuzzyOptions,omitempty"`
}

type TranscribeResult

type TranscribeResult func(text string, isLast bool, duration time.Duration, uuid string)

type TranscribeService

type TranscribeService interface {
	Init(tr TranscribeResult, er ProcessError)
	Vendor() string
	ConnAndReceive(dialogId string) error
	Activity() bool
	RestartClient()
	SendAudioBytes(data []byte) error
	SendEnd() error
	StopConn() error
}

type TranscriberConfig

type TranscriberConfig interface {
	GetVendor() Vendor
}

TranscriberConfig 统一的配置接口

func NewTranscriberConfigFromMap

func NewTranscriberConfigFromMap(
	provider string,
	config map[string]interface{},
	language string,
) (TranscriberConfig, error)

NewTranscriberConfigFromMap 从 map[string]interface{} 创建 TranscriberConfig 这是统一的配置入口,所有配置解析逻辑都在这里

type TranscriberFactory

type TranscriberFactory interface {
	// CreateTranscriber 根据配置创建 TranscribeService
	CreateTranscriber(config TranscriberConfig) (TranscribeService, error)
	// GetSupportedVendors 获取支持的供应商列表
	GetSupportedVendors() []Vendor
	// IsVendorSupported 检查供应商是否支持
	IsVendorSupported(vendor Vendor) bool
}

TranscriberFactory 工厂接口

type Transcript

type Transcript struct {
	Type          string            `json:"type"`
	Transcription string            `json:"transcription"`
	TimeBegin     float64           `json:"time_begin"`
	TimeEnd       float64           `json:"time_end"`
	Confidence    float64           `json:"confidence"`
	Language      string            `json:"language"`
	Utterances    []GladiaUtterance `json:"utterances"`
	RequestID     string            `json:"request_id"`
	InferenceTime float64           `json:"inference_time"`
	Duration      float64           `json:"duration"`
	Event         string            `json:"event"`
	Code          string            `json:"code"`
	Message       string            `json:"message"`
}

type UserConfig

type UserConfig struct {
	UID        string `json:"uid" yaml:"uid" default:"demo_uid"`
	DID        string `json:"did" yaml:"did"`
	Platform   string `json:"platform" yaml:"platform"`
	SDKVersion string `json:"sdk_version" yaml:"sdk_version"`
	APPVersion string `json:"app_version" yaml:"app_version"`
}

UserConfig represents user metadata configuration

type UserMeta

type UserMeta struct {
	UID        string `json:"uid,omitempty"`
	DID        string `json:"did,omitempty"`
	Platform   string `json:"platform,omitempty"`
	SDKVersion string `json:"sdk_version,omitempty"`
	APPVersion string `json:"app_version,omitempty"`
}

type Utterance

type Utterance struct {
	Text      string `json:"text"`
	StartTime int    `json:"start_time"`
	EndTime   int    `json:"end_time"`
	Definite  bool   `json:"definite"`
	Words     []Word `json:"words"`
	Language  string `json:"language"`
}

type Vendor

type Vendor string

Vendor 供应商类型

const (
	// VendorQCloud 腾讯云
	VendorQCloud Vendor = "qcloud"
	// VendorGoogle Google
	VendorGoogle Vendor = "google"
	// VendorAliyun 阿里云
	VendorAliyun Vendor = "aliyun"
	// VendorFunASR FunASR
	VendorFunASR Vendor = "funasr"
	// VendorVolcengine 火山引擎
	VendorVolcengine Vendor = "volcengine"
	// VendorVolcengineLLM 火山引擎LLM
	VendorVolcengineLLM Vendor = "volcllmasr"
	// VendorXfyunMul 科大讯飞多语言
	// 注意:Xfyun (非Mul版本) 未实现 TranscribeService 接口,只有 WithXfyunASR 函数
	VendorXfyunMul Vendor = "xfyun_mul"
	// VendorGladia Gladia
	VendorGladia Vendor = "gladia"
	// VendorFunASRRealtime FunASR实时
	VendorFunASRRealtime Vendor = "funasr_realtime"
	// VendorWhisper Whisper
	VendorWhisper Vendor = "whisper"
	// VendorDeepgram Deepgram
	VendorDeepgram Vendor = "deepgram"
	// VendorAWS AWS
	VendorAWS Vendor = "aws"
	// VendorBaidu 百度
	VendorBaidu Vendor = "baidu"
	// VendorVoiceAPI VoiceAPI
	VendorVoiceAPI Vendor = "voiceapi"
	// VendorLocal 本地ASR
	VendorLocal Vendor = "local"
)

func GetVendor

func GetVendor(provider string) Vendor

GetVendor 获取vendor枚举值(公开函数,供其他包使用)

type VoiceapiASR

type VoiceapiASR struct {
	Sentence string
	// contains filtered or unexported fields
}

type VoiceapiASROption

type VoiceapiASROption struct {
	Url         string `json:"url" yaml:"url" env:"ASR_VOICEAPI_URL"`
	ReqChanSize int    `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
}

func NewVoiceapiASROption

func NewVoiceapiASROption(url string) VoiceapiASROption

func (*VoiceapiASROption) GetVendor

func (opt *VoiceapiASROption) GetVendor() Vendor

type VoiceapiResponse

type VoiceapiResponse struct {
	Idx      int    `json:"idx"`
	Finished bool   `json:"finished"`
	Text     string `json:"text"`
}

type VolcEngineResponse

type VolcEngineResponse struct {
	Reqid    string             `json:"reqid"`
	Code     int                `json:"code"`
	Message  string             `json:"message"`
	Sequence int                `json:"sequence"`
	Results  []VolcengineResult `json:"result,omitempty"`
}

type Volcengine

type Volcengine struct {
	Sentence string
	// contains filtered or unexported fields
}

type VolcengineClient

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

func (*VolcengineClient) String

func (c *VolcengineClient) String() string

type VolcengineLLMASR

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

func NewVolcengineLLM

func NewVolcengineLLM(opt VolcengineLLMOption) VolcengineLLMASR

func (*VolcengineLLMASR) Activity

func (v *VolcengineLLMASR) Activity() bool

func (*VolcengineLLMASR) ConnAndReceive

func (v *VolcengineLLMASR) ConnAndReceive(dialogID string) error

func (*VolcengineLLMASR) Init

func (*VolcengineLLMASR) RestartClient

func (v *VolcengineLLMASR) RestartClient()

func (*VolcengineLLMASR) SendAudioBytes

func (v *VolcengineLLMASR) SendAudioBytes(data []byte) error

func (*VolcengineLLMASR) SendEnd

func (v *VolcengineLLMASR) SendEnd() error

func (*VolcengineLLMASR) StopConn

func (v *VolcengineLLMASR) StopConn() error

func (*VolcengineLLMASR) Vendor

func (v *VolcengineLLMASR) Vendor() string

type VolcengineLLMOption

type VolcengineLLMOption struct {
	Url         string    `json:"url" yaml:"url" default:"wss://openspeech.bytedance.com/api/v3/sauc/bigmodel_async"`
	ResourceId  string    `json:"resourceId" yaml:"resource_id" default:"volc.bigasr.sauc.duration"`
	AppID       string    `json:"appId" yaml:"app_id" env:"ASR_VOLC_LLM_APPID"`
	AccessToken string    `json:"accessToken" yaml:"access_token" env:"ASR_VOLC_LLM_ACCESS_TOKEN"`
	Format      string    `json:"format" yaml:"format" default:"pcm"`
	SampleRate  int       `json:"sampleRate" yaml:"sample_rate" default:"16000"`
	BitDepth    int       `json:"bitDepth" yaml:"bit_depth" default:"16"`
	Channel     int       `json:"channel" yaml:"channel" default:"1"`
	Codec       string    `json:"codec" yaml:"codec" default:"raw"`
	ReqChanSize int       `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
	HotWords    []HotWord `json:"hotWords" yaml:"hot_words"`
}

func NewVolcengineLLMOption

func NewVolcengineLLMOption(token, appID string) VolcengineLLMOption

func (*VolcengineLLMOption) GetVendor

func (opt *VolcengineLLMOption) GetVendor() Vendor

type VolcengineOption

type VolcengineOption struct {
	Url         string `json:"url" yaml:"url" default:"wss://openspeech.bytedance.com/api/v2/asr"`
	AppID       string `json:"appId" yaml:"app_id" env:"VOLC_APPID"`
	Token       string `json:"token" yaml:"token" env:"VOLC_TOKEN"`
	Cluster     string `json:"cluster" yaml:"cluster" env:"VOLC_CLUSTER"`
	WorkFlow    string `json:"workFlow" yaml:"work_flow" default:"audio_in,resample,partition,vad,fe,decode"`
	Format      string `json:"format" yaml:"format" default:"raw" env:"VOLC_FORMAT"`
	Codec       string `json:"codec" yaml:"codec" default:"raw"`
	ReqChanSize int    `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
}

func NewVolcengineOption

func NewVolcengineOption(appId string, token string, cluster string, format string) VolcengineOption

func (*VolcengineOption) GetVendor

func (opt *VolcengineOption) GetVendor() Vendor

type VolcengineResult

type VolcengineResult struct {
	Text       string      `json:"text"`
	Confidence int         `json:"confidence"`
	Language   string      `json:"language,omitempty"`
	Utterances []Utterance `json:"utterances,omitempty"`
}

type WAVHeader

type WAVHeader struct {
	ChunkID       [4]byte
	ChunkSize     uint32
	Format        [4]byte
	Subchunk1ID   [4]byte
	Subchunk1Size uint32
	AudioFormat   uint16
	NumChannels   uint16
	SampleRate    uint32
	ByteRate      uint32
	BlockAlign    uint16
	BitsPerSample uint16
	Subchunk2ID   [4]byte
	Subchunk2Size uint32
}

type WhisperASR

type WhisperASR struct {
	Sentence string
	EndTime  uint32
	// contains filtered or unexported fields
}

type WhisperASROption

type WhisperASROption struct {
	Url         string `json:"url" yaml:"url"`
	Model       string `json:"model" yaml:"model"`
	ReqChanSize int    `json:"reqChanSize" yaml:"req_chan_size" default:"128"`
}

func NewWhisperASROption

func NewWhisperASROption(url, model string) WhisperASROption

func (*WhisperASROption) GetVendor

func (opt *WhisperASROption) GetVendor() Vendor

type WhisperResult

type WhisperResult struct {
	IsFinal bool   `json:"is_final"`
	Text    string `json:"text"`
}

type Word

type Word struct {
	Text          string `json:"text"`
	StartTime     int    `json:"start_time"`
	EndTime       int    `json:"end_time"`
	Pronounce     string `json:"pronounce"`
	BlankDuration int    `json:"blank_duration"`
}

Jump to

Keyboard shortcuts

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