Documentation ¶
Index ¶
Constants ¶
const ( // BlockSizeNorthAmerica is the optimum block size for North America progress tones: 350 440 480 620 850 1400 1800 Hz BlockSizeNorthAmerica = 183 // BlockSizeSouthAmerica is the optimum block size for Costa Rica and Brazil: 425Hz BlockSizeSouthAmerica = 188 // BlockSizeUKDisconnect is the optimum block size for UK disconnect tone: 400Hz BlockSizeUKDisconnect = 160 // BlockSizeDTMF is the optimum block size for DTMF detection BlockSizeDTMF = 102 // RateTelephony is the standard telephony rate of 8kHz RateTelephony = 8000.0 // ToneThreshold is the standard threshold for tone detection ToneThreshold = 7.8e7 )
Variables ¶
var BlockBufferSize = 50
BlockBufferSize is the number of blocks to buffer for slow readers, when sending BlockSummaries from Targets
var ContactIDFrequencies = []float64{1400.0, 2300.0}
ContactIDFrequencies is the list of signaling frequencies used in SIA ContactID
var DTMFFrequencies = []float64{697.0, 770.0, 852.0, 941.0, 1209.0, 1336.0, 1477.0, 1633.0}
DTMFFrequencies is the list of frequencies used by standard North American DTMF
var NATelephonyFrequencies = []float64{350.0, 440.0, 480.0, 620.0, 850.0, 1400.0, 1800.0}
NATelephonyFrequencies is the list of common frequencies used in the North American telephony space
Functions ¶
func DetectTone ¶
func DetectTone(ctx context.Context, freq, sampleRate float64, minDuration time.Duration, in io.Reader) (found bool, err error)
DetectTone waits for the given tone to be found, returning with `true` when it is. `false` will be returned if canceled by context or by a stream error/completion.
Types ¶
type BlockSummary ¶
type BlockSummary struct { // Magnitude2 is the square of the relative magnitude of the frequency in this block Magnitude2 float64 // Frequency is the frequency which was being detected Frequency float64 // Duration is the elapsed time which this block represents Duration time.Duration // Samples is the number of samples this block represents Samples int // Present indicates whether the frequency was found in the block, as determined by the target's threshold Present bool }
BlockSummary describes the result of a single block of processing for a Target frequency
type Target ¶
type Target struct { // UseOptimized indicates that an optimized (phase-insensitive) Goertzel should be used for faster arithmetic UseOptimized bool // Frequency in Hz Frequency float64 // Threshold is the threshold at which this frequency is determined to be present Threshold float64 // Magnitude2 is the square of the magnitude of the last-processed block Magnitude2 float64 // contains filtered or unexported fields }
Target is a target frequency detector. It is a low-level tool which implements the Goertzel algorithm to detect the presence of a frequency on a block-wise basis.
func (*Target) Blocks ¶
func (t *Target) Blocks() <-chan *BlockSummary
Blocks returns a channel over which the summary of each resulting block from the Target frequency processor will be returned. If Blocks() has already been called, nil will be returned.
func (*Target) SetBlockSize ¶
SetBlockSize overrides automatic calculation of the optimal N (block size) value and uses the one provided instead