talk

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package talk plays audio from an RTSP client through a camera's speaker.

The camera side is internal/baichuan's: OpenTalk negotiates the session and Talk carries the blocks. What this package adds is the conversion between the two ends. An RTSP back channel arrives as G.711 at 8 kHz in packets of whatever size the client chose; the cameras surveyed here take IMA ADPCM at 16 kHz in blocks of exactly 1024 samples. So audio is resampled to the camera's rate, collected until a whole block is there, and sent a block at a time.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("talk: session closed")

ErrClosed is Write after Close.

Functions

func Listen added in v0.2.16

func Listen(camera string) (<-chan []int16, func())

Listen gives silence, in blocks of 1024 samples at 16 kHz paced by the camera's own talk return, while someone talking through the camera has spoken within muteHold; nothing arrives otherwise. A listener that falls behind loses blocks rather than holding the talk session up.

func LiveMute added in v0.2.18

func LiveMute(camera string, pcm []int16, at time.Time) bool

LiveMute says whether a live player should have pcm, the camera's stream sound decoded at 16 kHz and arrived at at, muted because it carries the talker's own voice. It also learns from pcm, so a live player calls it for everything it plays, muted or not.

func LiveReturn added in v0.2.18

func LiveReturn(camera string) (<-chan []int16, func())

LiveReturn gives camera's microphone during talk, 1024 samples at 16 kHz every 64 ms as the camera sends them, with the talker's own voice silenced; nothing arrives outside talk, or from a camera whose talk return does not parse. A listener that falls behind loses blocks rather than holding the talk session up.

func Speaking added in v0.2.18

func Speaking(camera string) bool

Speaking reports whether someone talking through camera has spoken within muteHold, the same signal Listen gives, for a player that would rather ask than be told: the RTSP Opus path, read live by go2rtc.

Types

type Dialer

type Dialer func(ctx context.Context) (*baichuan.Conn, error)

Dialer opens a fresh connection to one camera.

type Session

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

Session is one talk session on its own camera connection, separate from the ones carrying video, so talking never risks a stream.

func Open

func Open(ctx context.Context, dial Dialer) (*Session, error)

Open dials the camera and negotiates a talk session.

func (*Session) Close

func (s *Session) Close() error

Close sends what is left, padded to a block, and releases the camera.

func (*Session) Ping

func (s *Session) Ping() error

Ping keeps the connection alive between bursts of speech. The camera sends nothing back during a talk session, and a connection that hears nothing for baichuan.DefaultIdleTimeout gives up on itself.

func (*Session) Returns added in v0.2.16

func (s *Session) Returns() <-chan baichuan.TalkReturn

Returns gives the camera's talk return blocks, in order, until the session closes. A camera whose returns do not parse sends nothing here.

func (*Session) SetGain added in v0.2.6

func (s *Session) SetGain(db int)

SetGain sets the talk gain in dB (config talk_gain_db) for what Write sends from now on.

func (*Session) Share added in v0.2.16

func (s *Session) Share(camera string)

Share tells camera's live listeners someone is talking, a block of silence for each block the camera sends back while the talker has spoken within muteHold. Call once, right after Open.

func (*Session) Write

func (s *Session) Write(inRate int, pcm []int16) error

Write plays pcm, 16 bit mono at inRate, through the camera. Samples short of a whole block wait for the next call.

Jump to

Keyboard shortcuts

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