speaker

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package speaker implements playback of beep.Streamer values through physical speakers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(sampleRate beep.SampleRate) error

Init initializes audio playback through speaker. Must be called before using this package.

func Play

func Play(s ...beep.Streamer)

Play starts playing all provided Streamers through the speaker. Each player will be closed automatically after the streamer ends.

Play is a convenience function for (some) backwards compatibility. To have more control, use NewPlayer() instead.

func Resume added in v1.0.3

func Resume() error

Resume audio playback after it was suspended by Suspend().

Resume is concurrent-safe.

func Suspend added in v1.0.3

func Suspend() error

Suspend audio playback until Resume() is called.

Suspend is concurrent-safe.

Types

type Player added in v1.0.3

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

Player gives control over the playback of the Steamer.

func NewPlayer added in v1.0.3

func NewPlayer(s beep.Streamer) Player

NewPlayer creates a Player from a Streamer. Player can be used to finely control playback of the stream. A player has an internal buffer that will be filled by pulling samples from Streamer and will be drained by the audio being played. So their position won't necessarily match exactly. If you want to clear the underlying buffer for some reasons e.g., you want to seek the position of s, call the player's Reset() function. NewPlayer is concurrent safe, however s cannot be used by multiple players.

func (*Player) Close added in v1.0.3

func (s *Player) Close() error

Close the player and remove it from the speaker. Streamer is *not* closed.

func (*Player) DurationPlayed added in v1.0.3

func (s *Player) DurationPlayed() time.Duration

DurationPlayed returns the playtime of this player based on the samples played and the sample rate speaker was initialized with. If the player is in a paused state, this will not increase.

func (*Player) Err added in v1.0.3

func (s *Player) Err() error

Err returns an error if this player has an error.

func (*Player) IsPlaying added in v1.0.3

func (s *Player) IsPlaying() bool

IsPlaying reports whether this player is playing.

func (*Player) Pause added in v1.0.3

func (s *Player) Pause()

Pause the player.

func (*Player) Play added in v1.0.3

func (s *Player) Play()

Play resumes playing after playback was paused.

func (*Player) Reset added in v1.0.3

func (s *Player) Reset()

Reset clears the underlying buffer and pauses its playing. This can be useful when you want to Seek() or make other modifications to the Streamer. In this case, call Reset() before seeking or other functions. Reset will also reset SamplesPlayed and DurationPlayed.

func (*Player) SamplesPlayed added in v1.0.3

func (s *Player) SamplesPlayed() int

SamplesPlayed returns the total number of samples played through this player. If the player is in a paused state, this will not increase.

func (*Player) SetVolume added in v1.0.3

func (s *Player) SetVolume(v float64)

SetVolume sets the current volume in the range of [0, 1].

func (*Player) UnplayedBufferSize added in v1.0.3

func (s *Player) UnplayedBufferSize() int

UnplayedBufferSize returns the byte size in the underlying buffer that is not played yet.

func (*Player) Volume added in v1.0.3

func (s *Player) Volume() float64

Volume returns the current volume in the range of [0, 1]. The default volume is 1. TODO: allow changing/reading volume in other bases. See Beep's Volume effect.

Jump to

Keyboard shortcuts

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