mrcp

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: BSD-2-Clause Imports: 17 Imported by: 0

README

go-mrcp

Go Report Card PkgGoDev License

A pure Go MRCPv2 library.


The library is under development and the API may change or be removed in future versions.


Features

  • MRCPv2 client
  • MRCPv2 server
  • MRCPv2 proxy
  • MRCPv2 TLS

Examples

Documentation

Index

Constants

View Source
const (
	ProtoTCP = "TCP/MRCPv2"
	ProtoTLS = "TCP/TLS/MRCPv2"

	SetupActive  = "active"
	SetupPassive = "passive"

	ConnectionNew      = "new"
	ConnectionExisting = "existing"
)
View Source
const (
	MethodRecognize             = "RECOGNIZE"
	MethodSetParams             = "SET-PARAMS"
	MethodGetParams             = "GET-PARAMS"
	MethodDefineGrammar         = "DEFINE-GRAMMAR"
	MethodInterpret             = "INTERPRET"
	MethodGetResult             = "GET-RESULT"
	MethodStartInputTimers      = "START-INPUT-TIMERS"
	MethodStop                  = "STOP"
	MethodStartPhraseEnrollment = "START-PHRASE-ENROLLMENT"
	MethodEnrollmentRollback    = "ENROLLMENT-ROLLBACK"
	MethodEndPhraseEnrollment   = "END-PHRASE-ENROLLMENT"
	MethodModifyPhrase          = "MODIFY-PHRASE"
	MethodDeletePhrase          = "DELETE-PHRASE"
	MethodSpeak                 = "SPEAK"
	MethodPause                 = "PAUSE"
	MethodResume                = "RESUME"
	MethodBargeInOccurred       = "BARGE-IN-OCCURRED"
	MethodControl               = "CONTROL"
	MethodDefineLexicon         = "DEFINE-LEXICON"
)
View Source
const (
	HeaderContentType       = "Content-Type"
	HeaderContentLength     = "Content-Length"
	HeaderCompletionCause   = "Completion-Cause"
	HeaderChannelIdentifier = "Channel-Identifier"
)
View Source
const (
	RequestStateComplete   = "COMPLETE"
	RequestStateInProgress = "IN-PROGRESS"
	RequestStatePending    = "PENDING"
)
View Source
const (
	CodecTelephoneEvent = "telephone-event"
)

Variables

View Source
var (
	ErrNoFreePorts = errors.New("no free rtp ports")
)

Functions

This section is empty.

Types

type Channel

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

func (*Channel) Close

func (c *Channel) Close() error

func (*Channel) GetChannelId

func (c *Channel) GetChannelId() ChannelId

func (*Channel) GetResource

func (c *Channel) GetResource() Resource

func (*Channel) NewEvent

func (c *Channel) NewEvent(event, requestState string) Message

func (*Channel) NewRequest

func (c *Channel) NewRequest(method string) Message

func (*Channel) NewResponse

func (c *Channel) NewResponse(msg Message, statusCode int, requestState string) Message

func (*Channel) SendMrcpMessage

func (c *Channel) SendMrcpMessage(msg Message) error

TODO: check Channel inused

func (*Channel) SetChannelId added in v1.0.1

func (c *Channel) SetChannelId(id ChannelId)

type ChannelHandler

type ChannelHandler interface {
	// OnMessage on receive mrcp message
	OnMessage(c *Channel, msg Message)
}

type ChannelHandlerFunc

type ChannelHandlerFunc struct {
	// OnMessageFunc mrcp response
	OnMessageFunc func(c *Channel, msg Message)
}

func (ChannelHandlerFunc) OnMessage

func (h ChannelHandlerFunc) OnMessage(c *Channel, msg Message)

type ChannelId

type ChannelId struct {
	Id       string
	Resource Resource
}

func (ChannelId) String

func (c ChannelId) String() string

type Client

type Client struct {
	// Host local host
	// default: 127.0.0.1
	Host string
	// SIPPort SIP server port
	// default: 5060
	SIPPort int
	// UserAgent SIP User-Agent
	UserAgent string
	// AudioCodecs audio codecs
	// Default: defaultAudioCodecs
	AudioCodecs []CodecDesc
	// RtpPortMin RtpPortMax RTP port range
	// Default: [20000, 40000)
	RtpPortMin, RtpPortMax uint16
	// Logger
	// Default: slog.Default
	Logger *slog.Logger
	// contains filtered or unexported fields
}

func (*Client) Close

func (c *Client) Close() error

func (*Client) Dial

func (c *Client) Dial(
	raddr string,
	resource Resource,
	handler DialogHandler,
	opts ...DialogClientOptionFunc,
) (*DialogClient, error)

func (*Client) Run

func (c *Client) Run() error

type CodecDesc

type CodecDesc struct {
	PayloadType  int
	Name         string
	SampleRate   int
	FormatParams map[string]string
}

type CompletionCause

type CompletionCause int
const (
	SynthCompletionCauseNormal CompletionCause = iota
	SynthCompletionCauseBargeIn
	SynthCompletionCauseParseFailure
	SynthCompletionCauseUriFailure
	SynthCompletionCauseError
	SynthCompletionCauseLanguageUnsupported
	SynthCompletionCauseLexiconLoadFailure
	SynthCompletionCauseCancelled
)
const (
	RecogCompletionCauseSuccess CompletionCause = iota
	RecogCompletionCauseNoMatch
	RecogCompletionCauseNoInputTimeout
	RecogCompletionCauseHotWordMaxTime
	RecogCompletionCauseGrammarLoadFailure
	RecogCompletionCauseGrammarCompilationFailure
	RecogCompletionCauseRecognizerError
	RecogCompletionCauseSpeechTooEarly
	RecogCompletionCauseSuccessMaxTime
	RecogCompletionCauseUriFailure
	RecogCompletionCauseLanguageUnsupported
	RecogCompletionCauseCancelled
	RecogCompletionCauseSemanticsFailure
	RecogCompletionCausePartialMatch
	RecogCompletionCausePartialMatchMaxTime
	RecogCompletionCauseNoMatchMaxTime
	RecogCompletionCauseGrammarDefinitionFailure
)

func (CompletionCause) Marshal

func (c CompletionCause) Marshal(resource Resource) string

type ControlDesc

type ControlDesc struct {
	// Host The connection-address in the SDP Connection field
	Host           string
	Port           int
	Proto          string
	SetupType      string
	ConnectionType string
	ChannelId      ChannelId
	Resource       Resource
}

type Desc

type Desc struct {
	// UserAgent The username in the SDP Origin field
	UserAgent string
	// Host The global connection-address in the SDP Connection field
	Host        string
	AudioDesc   MediaDesc
	ControlDesc ControlDesc
}

Desc SDP

type DialogClient

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

func (*DialogClient) Close

func (d *DialogClient) Close() error

func (*DialogClient) GetChannel

func (d *DialogClient) GetChannel() *Channel

func (*DialogClient) GetLocalDesc added in v1.0.1

func (d *DialogClient) GetLocalDesc() *Desc

func (*DialogClient) GetRemoteDesc added in v1.0.1

func (d *DialogClient) GetRemoteDesc() *Desc

type DialogClientOptionFunc added in v1.0.1

type DialogClientOptionFunc func(d *DialogClient)

func WithAudioCodecs added in v1.0.1

func WithAudioCodecs(codecs []CodecDesc) DialogClientOptionFunc

type DialogHandler

type DialogHandler interface {
	OnMediaOpen(media *Media) MediaHandler
	OnChannelOpen(channel *Channel) ChannelHandler
	OnClose()
}

type DialogHandlerFunc

type DialogHandlerFunc struct {
	OnMediaOpenFunc   func(media *Media) MediaHandler
	OnChannelOpenFunc func(channel *Channel) ChannelHandler
	OnCloseFunc       func()
}

func (DialogHandlerFunc) OnChannelOpen

func (h DialogHandlerFunc) OnChannelOpen(channel *Channel) ChannelHandler

func (DialogHandlerFunc) OnClose added in v1.0.1

func (h DialogHandlerFunc) OnClose()

func (DialogHandlerFunc) OnMediaOpen

func (h DialogHandlerFunc) OnMediaOpen(media *Media) MediaHandler

type DialogServer

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

func (*DialogServer) Close

func (d *DialogServer) Close() error

func (*DialogServer) GetChannel added in v1.0.1

func (d *DialogServer) GetChannel() *Channel

func (*DialogServer) GetLocalDesc added in v1.0.1

func (d *DialogServer) GetLocalDesc() *Desc

func (*DialogServer) GetRemoteDesc added in v1.0.1

func (d *DialogServer) GetRemoteDesc() *Desc

func (*DialogServer) GetResource added in v1.0.2

func (d *DialogServer) GetResource() Resource

type Direction

type Direction string
const (
	DirectionSendonly Direction = "sendonly"
	DirectionRecvonly Direction = "recvonly"
	DirectionSendrecv Direction = "sendrecv"
	DirectionInactive Direction = "inactive"
)

type Media

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

func (*Media) Close

func (m *Media) Close() error

func (*Media) LocalAudioDesc

func (m *Media) LocalAudioDesc() MediaDesc

func (*Media) RemoteAudioDesc

func (m *Media) RemoteAudioDesc() MediaDesc

type MediaDesc

type MediaDesc struct {
	// Host The connection-address in the SDP Connection field
	Host      string
	Port      int
	Direction Direction
	Ptime     int
	Codecs    []CodecDesc
}

type MediaHandler

type MediaHandler interface {
	// StartTx is called when starting to send RTP stream
	StartTx(m *Media, codec CodecDesc) error
	// ReadRTPPacket read a RTP packet from high-level
	// stop sending by returning false
	ReadRTPPacket(m *Media) ([]byte, bool)

	// StartRx is called when starting to receive RTP stream
	StartRx(m *Media, codec CodecDesc) error
	// WriteRTPPacket write a RTP packet to high-level
	// stop receiving by returning false
	WriteRTPPacket(m *Media, rtp []byte) bool
}

type MediaHandlerFunc

type MediaHandlerFunc struct {
	StartTxFunc        func(m *Media, codec CodecDesc) error
	ReadRTPPacketFunc  func(m *Media) ([]byte, bool)
	StartRxFunc        func(m *Media, codec CodecDesc) error
	WriteRTPPacketFunc func(m *Media, rtp []byte) bool
}

func (MediaHandlerFunc) ReadRTPPacket

func (h MediaHandlerFunc) ReadRTPPacket(m *Media) ([]byte, bool)

func (MediaHandlerFunc) StartRx

func (h MediaHandlerFunc) StartRx(m *Media, codec CodecDesc) error

func (MediaHandlerFunc) StartTx

func (h MediaHandlerFunc) StartTx(m *Media, codec CodecDesc) error

func (MediaHandlerFunc) WriteRTPPacket

func (h MediaHandlerFunc) WriteRTPPacket(m *Media, rtp []byte) bool

type Message

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

func Unmarshal

func Unmarshal(msg []byte) (Message, error)

func (*Message) GetBody

func (m *Message) GetBody() []byte

func (*Message) GetCompletionCause

func (m *Message) GetCompletionCause() CompletionCause

func (*Message) GetHeader

func (m *Message) GetHeader(key string) string

func (*Message) GetMessageType

func (m *Message) GetMessageType() MessageType

func (*Message) GetName

func (m *Message) GetName() string

func (*Message) GetRequestId

func (m *Message) GetRequestId() uint32

func (*Message) GetRequestState

func (m *Message) GetRequestState() string

func (*Message) GetStatusCode

func (m *Message) GetStatusCode() int

func (*Message) Marshal

func (m *Message) Marshal() []byte

func (*Message) SetBody

func (m *Message) SetBody(body []byte, contentType string)

func (*Message) SetCompletionCause

func (m *Message) SetCompletionCause(resource Resource, cc CompletionCause)

func (*Message) SetHeader

func (m *Message) SetHeader(k, v string)

func (*Message) SetRequestId

func (m *Message) SetRequestId(requestId uint32)

type MessageType

type MessageType uint8
const (
	MessageTypeRequest MessageType = 1 + iota
	MessageTypeResponse
	MessageTypeEvent
)

func (MessageType) String added in v1.0.2

func (m MessageType) String() string

type Resource

type Resource string
const (
	ResourceSpeechsynth Resource = "speechsynth"
	ResourceSpeechrecog Resource = "speechrecog"
)

type Server

type Server struct {
	// Host local host
	// default: 127.0.0.1
	Host string
	// SIPPort SIP server port
	// default: 5060
	SIPPort int
	// MRCPPort MRCP server port
	// default: 1544
	MRCPPort int
	// UserAgent SIP User-Agent
	UserAgent string
	// AudioCodecs audio codecs
	// Default: defaultAudioCodecs
	AudioCodecs []CodecDesc
	// RtpPortMin RtpPortMax RTP port range
	// Default: [20000, 40000)
	RtpPortMin, RtpPortMax uint16
	// Handler handler
	Handler ServerHandler
	// Logger
	// Default: slog.Default
	Logger *slog.Logger
	// contains filtered or unexported fields
}

func (*Server) Close added in v1.0.1

func (s *Server) Close() error

func (*Server) Run

func (s *Server) Run() error

type ServerHandler

type ServerHandler interface {
	OnDialogCreate(d *DialogServer) (DialogHandler, error)
}

type ServerHandlerFunc

type ServerHandlerFunc struct {
	OnDialogCreateFunc func(d *DialogServer) (DialogHandler, error)
}

func (ServerHandlerFunc) OnDialogCreate

func (h ServerHandlerFunc) OnDialogCreate(d *DialogServer) (DialogHandler, error)

Directories

Path Synopsis
pkg
pcm

Jump to

Keyboard shortcuts

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