x

package
v0.0.0-...-8a010fa Latest Latest
Warning

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

Go to latest
Published: May 8, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TCPPort = 11024
	UDPPort = 11025
)
View Source
const (
	StatusInit = iota
	StatusStart
	StatusEnd
)
View Source
const (
	CmdStart = "S"
	CmdEnd   = "E"

	TypeRspStart      = "RS"
	TypeRspEnd        = "RE"
	TypeStop          = "STOP" // 代表关闭会话
	TypeSentenceStart = "SS"
	TypeRecognizing   = "R"
	TypeSentenceEnd   = "SE"
)
View Source
const (
	UDPSendLen = 1460
)

Variables

View Source
var (
	ErrClient          = errors.New("x client error")
	ErrNoLooping       = fmt.Errorf("%w, %s", ErrClient, "no looping read")
	ErrNotStart        = fmt.Errorf("%w, %s", ErrClient, "status not start")
	ErrStartRspTimeOut = fmt.Errorf("%w, %s", ErrClient, "start response timeout")
	ErrEndRspTimeOut   = fmt.Errorf("%w, %s", ErrClient, "end response timeout")
	ErrNotEnd          = fmt.Errorf("%w, %s", ErrClient, "status not end")
)

Functions

This section is empty.

Types

type AllRequest

type AllRequest struct {
	Cmd    string      `json:"cmd"`
	Config StartConfig `json:"config,omitempty"`
}

type AllResponse

type AllResponse struct {
	Type            string          `json:"type"`
	SessionID       uint32          `json:"sessionID"`
	TaskID          string          `json:"taskID"`
	UDPPort         int32           `json:"udpPort"`
	Error           Error           `json:"error,omitempty"`
	Result          RecognizeResult `json:"result,omitempty"`
	StartResult     StartResult     `json:"startResult,omitempty"`
	ConnectionClose bool            `json:"connectionClose"`
}

type AsrResultCallBack

type AsrResultCallBack func(rsp *AllResponse) error

type Client

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

func NewClient

func NewClient(agentAddr string, cb AsrResultCallBack) (*Client, error)

NewClient TODO 处理返回结果

func (*Client) Close

func (c *Client) Close()

func (*Client) End

func (c *Client) End() error

func (*Client) Send

func (c *Client) Send(data []byte) (err error)

func (*Client) Start

func (c *Client) Start(conf StartConfig) error

type Conf

type Conf struct {
	TcpPort int
	UdpPort int
}

type End

type End struct {
	Cmd string `json:"cmd"`
}

type EndResponse

type EndResponse struct {
	Type  string `json:"type"`
	Error Error  `json:"error,omitempty"`
}

type Error

type Error struct {
	Msg string `json:"msg"`
}

type FakeSession

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

func (*FakeSession) CloseAll

func (f *FakeSession) CloseAll()

func (*FakeSession) CommandCb

func (f *FakeSession) CommandCb(allResponse *AllRequest) error

func (*FakeSession) DataCb

func (f *FakeSession) DataCb(data []byte, seq uint32)

func (*FakeSession) ID

func (f *FakeSession) ID() uint32

type FakeSessionMaker

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

func NewFakeSessionMaker

func NewFakeSessionMaker() *FakeSessionMaker

func (*FakeSessionMaker) MakeSession

func (f *FakeSessionMaker) MakeSession(response IResponse) (ISession, error)

type IResponse

type IResponse interface {
	Write([]byte) (int, error)
}

type ISession

type ISession interface {
	ID() uint32
	CommandCb(allResponse *AllRequest) error
	DataCb(data []byte, seq uint32)
	CloseAll()
}

type ISessionMaker

type ISessionMaker interface {
	MakeSession(IResponse) (ISession, error)
}

type Option

type Option func(s *Server)

func WithOptionSessionMaker

func WithOptionSessionMaker(sm ISessionMaker) Option

type RecognizeResult

type RecognizeResult struct {
	Interim    bool    `json:"interim"`
	Index      int     `json:"index"`
	Time       int     `json:"time"`
	Result     string  `json:"result"`
	Confidence float64 `json:"confidence"`
	Words      []Words `json:"words,omitempty"`
}

type RecognizingResponse

type RecognizingResponse struct {
	Type   string          `json:"type"`
	Result RecognizeResult `json:"result"`
}

type SentenceEndResponse

type SentenceEndResponse struct {
	Type   string          `json:"type"`
	Result RecognizeResult `json:"result"`
}

type SentenceStartResponse

type SentenceStartResponse struct {
	Type        string      `json:"type"`
	StartResult StartResult `json:"startResult"`
}

type Server

type Server struct {
	Conf
	// contains filtered or unexported fields
}

func NewServer

func NewServer(conf Conf, opts ...Option) *Server

func (*Server) Close

func (s *Server) Close()

func (*Server) Start

func (s *Server) Start() error

type Start

type Start struct {
	Cmd    string      `json:"cmd"`
	Config StartConfig `json:"config"`
}

type StartConfig

type StartConfig struct {
	SampleRate    int32 `json:"sampleRate"`
	BitsPerSample int32 `json:"bitsPerSample"`
}

type StartResponse

type StartResponse struct {
	Type      string `json:"type"`
	SessionID uint32 `json:"sessionID"`
	TaskID    string `json:"taskID"`
	UDPPort   int32  `json:"udpPort"`
	Error     Error  `json:"error,omitempty"`
}

type StartResult

type StartResult struct {
	Index int `json:"index"`
	Time  int `json:"time"`
}

type StopResponse

type StopResponse struct {
	Type            string `json:"type"`
	Error           Error  `json:"error,omitempty"`
	ConnectionClose bool   `json:"connectionClose"`
}

type TCPResponse

type TCPResponse struct {
	Conn net.Conn
}

func (*TCPResponse) Close

func (t *TCPResponse) Close()

func (*TCPResponse) Write

func (t *TCPResponse) Write(data []byte) (int, error)

type Words

type Words struct {
	Text      string `json:"text"`
	Starttime int    `json:"startTime"`
	Endtime   int    `json:"endTime"`
}

Jump to

Keyboard shortcuts

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