BackgroundAudio 1.3.3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
BackgroundAudioSpeechClass< DataBuffer > Class Template Reference

Interrupt-driven ESpeak-NG instance. Generates a full frame of samples each cycle and uses the RawBuffer to safely hand data from the app to the decompressor. More...

#include <BackgroundAudioSpeech.h>

Public Member Functions

 BackgroundAudioSpeechClass (AudioOutputBase &d)
 Construct an output device using the specified physical audio output.
 
bool setDevice (AudioOutputBase *d)
 Set an output device before begin
 
void setGain (float scale)
 Set the gain multiplier (volume) for the stream. Takes effect immediately.
 
void setVoice (BackgroundAudioVoice &v)
 Sets the voice parameters (language customization)
 
void setRate (int rate)
 Set the speaking rate in ~wpm, after calling begin()
 
void setPitch (int pitch)
 Adjust the pitch, 0...99, with 50 default. After begin()
 
void setWordGap (int gap)
 Adjust the interword gap after begin()
 
bool begin ()
 Starts the background speaker. Will initialize the output device and start sending silence immediately.
 
void end ()
 Stops the process and the calls the output device's end to shut it down, too.
 
bool playing ()
 Determines if the speaker has been started.
 
size_t write (const void *data, size_t len)
 Writes a block of raw data to the decoder's buffer.
 
size_t speak (const char *string)
 Speaks a C-String.
 
size_t speak (const String &string)
 Speaks an Arduino String.
 
size_t availableForWrite ()
 Gets number of bytes available to write to raw buffer.
 
size_t available ()
 Gets number of bytes already in the raw buffer.
 
bool done ()
 Determine if no more speech is present in the buffer.
 
uint32_t frames ()
 Get number of "frames" processed by speaker.
 
uint32_t shifts ()
 Get the number of input data shifts processed by decoder since begin
 
uint32_t underflows ()
 Get the number of times the speaker has underflowed waiting on raw data since begin
 
uint32_t errors ()
 Get the number of decoder errors since begin
 
uint32_t dumps ()
 Get the number of full buffer dumps (catastrophic data error) since begin
 
void pause ()
 Pause the decoder. Won't process raw input data and will transmit silence.
 
bool paused ()
 Determine if the playback is paused.
 
void unpause ()
 Unpause previously paused playback. Will start processing input data again.
 
void flush ()
 Flushes any existing raw data, resets the processor to start a new speaking.
 

Detailed Description

template<class DataBuffer>
class BackgroundAudioSpeechClass< DataBuffer >

Interrupt-driven ESpeak-NG instance. Generates a full frame of samples each cycle and uses the RawBuffer to safely hand data from the app to the decompressor.

Template Parameters
DataBufferThe type of raw data buffer, either normal RawDataBuffer or ROMDataBuffer as appropriate.

Constructor & Destructor Documentation

◆ BackgroundAudioSpeechClass()

template<class DataBuffer >
BackgroundAudioSpeechClass< DataBuffer >::BackgroundAudioSpeechClass ( AudioOutputBase &  d)
inline

Construct an output device using the specified physical audio output.

Parameters
[in]dAudioOutputBase device to send data to (or AudioMixerInput)

Member Function Documentation

◆ available()

template<class DataBuffer >
size_t BackgroundAudioSpeechClass< DataBuffer >::available ( )
inline

Gets number of bytes already in the raw buffer.

Returns
Bytes of raw data in the buffer

◆ availableForWrite()

template<class DataBuffer >
size_t BackgroundAudioSpeechClass< DataBuffer >::availableForWrite ( )
inline

Gets number of bytes available to write to raw buffer.

For ROM buffers, this is always 0 after a write has happened. Because ROM buffers don't actually allocate any RAM for buffering and simply store the pointer passed in from write there is no real space available for an app to write to. An app can simply flush and write a new complete buffer if needed ignoring availableForWrite in the ROM case.

Returns
Bytes that can be written

◆ begin()

template<class DataBuffer >
bool BackgroundAudioSpeechClass< DataBuffer >::begin ( )
inline

Starts the background speaker. Will initialize the output device and start sending silence immediately.

Returns
True on success, false if already started.

◆ done()

template<class DataBuffer >
bool BackgroundAudioSpeechClass< DataBuffer >::done ( )
inline

Determine if no more speech is present in the buffer.

Returns
True if no raw strings still left to process

◆ dumps()

template<class DataBuffer >
uint32_t BackgroundAudioSpeechClass< DataBuffer >::dumps ( )
inline

Get the number of full buffer dumps (catastrophic data error) since begin

Returns
Number of complete buffer throw-aways

◆ errors()

template<class DataBuffer >
uint32_t BackgroundAudioSpeechClass< DataBuffer >::errors ( )
inline

Get the number of decoder errors since begin

Returns
Number of decode errors encountered

◆ flush()

template<class DataBuffer >
void BackgroundAudioSpeechClass< DataBuffer >::flush ( )
inline

Flushes any existing raw data, resets the processor to start a new speaking.

This is only needed to abort a currently speaking phrase. Multiple strings can be sent in one after the other with write or speak

◆ frames()

template<class DataBuffer >
uint32_t BackgroundAudioSpeechClass< DataBuffer >::frames ( )
inline

Get number of "frames" processed by speaker.

Returns
Number of frames, where frames are framelen stereo samples in size

◆ paused()

template<class DataBuffer >
bool BackgroundAudioSpeechClass< DataBuffer >::paused ( )
inline

Determine if the playback is paused.

Returns
True of WAV playback has been paused

◆ playing()

template<class DataBuffer >
bool BackgroundAudioSpeechClass< DataBuffer >::playing ( )
inline

Determines if the speaker has been started.

Returns
True if running

◆ setDevice()

template<class DataBuffer >
bool BackgroundAudioSpeechClass< DataBuffer >::setDevice ( AudioOutputBase *  d)
inline

Set an output device before begin

Parameters
[in]dPointer to AudioOutputDevice to send decoded data to
Returns
True on success

◆ setGain()

template<class DataBuffer >
void BackgroundAudioSpeechClass< DataBuffer >::setGain ( float  scale)
inline

Set the gain multiplier (volume) for the stream. Takes effect immediately.

Parameters
[in]scaleFloating point value from 0.0....16.0 to multiply all audio data by

◆ setPitch()

template<class DataBuffer >
void BackgroundAudioSpeechClass< DataBuffer >::setPitch ( int  pitch)
inline

Adjust the pitch, 0...99, with 50 default. After begin()

Parameters
[in]pitchPitch setting

◆ setRate()

template<class DataBuffer >
void BackgroundAudioSpeechClass< DataBuffer >::setRate ( int  rate)
inline

Set the speaking rate in ~wpm, after calling begin()

Parameters
[in]rateWPM rate

◆ setVoice()

template<class DataBuffer >
void BackgroundAudioSpeechClass< DataBuffer >::setVoice ( BackgroundAudioVoice v)
inline

Sets the voice parameters (language customization)

Parameters
[in]vVoice (voice_xxx) included from in libespeak-ng/dict folder

◆ setWordGap()

template<class DataBuffer >
void BackgroundAudioSpeechClass< DataBuffer >::setWordGap ( int  gap)
inline

Adjust the interword gap after begin()

Parameters
[in]gapGap in ~10ms units at normal rate

◆ shifts()

template<class DataBuffer >
uint32_t BackgroundAudioSpeechClass< DataBuffer >::shifts ( )
inline

Get the number of input data shifts processed by decoder since begin

Returns
Number of times data has been shifted in the raw input buffer

◆ speak() [1/2]

template<class DataBuffer >
size_t BackgroundAudioSpeechClass< DataBuffer >::speak ( const char *  string)
inline

Speaks a C-String.

Parameters
[in]stringThe string to speak. Data is copied so this string can disappear afterwards
Returns
Number of bytes actually written to the buffer, or 0 on error (out of space)

◆ speak() [2/2]

template<class DataBuffer >
size_t BackgroundAudioSpeechClass< DataBuffer >::speak ( const String &  string)
inline

Speaks an Arduino String.

Parameters
[in]stringThe string to speak. Data is copied so this string can disappear afterwards
Returns
Number of bytes actually written to the buffer, or 0 on error (out of space)

◆ underflows()

template<class DataBuffer >
uint32_t BackgroundAudioSpeechClass< DataBuffer >::underflows ( )
inline

Get the number of times the speaker has underflowed waiting on raw data since begin

Returns
Number of frames of underflow data have occurred

◆ write()

template<class DataBuffer >
size_t BackgroundAudioSpeechClass< DataBuffer >::write ( const void *  data,
size_t  len 
)
inline

Writes a block of raw data to the decoder's buffer.

Copies up to len bytes into the raw buffer for the object. Can be called before begin, and can write less fewer than the number of bytes requested if there is not enough space. Will not block.

For ROM buffers this does not actually copy data, only the pointer. Therefore, for ROM buffers you cannot concatenate data by calling multiple writes because the second write will throw out all the data from the first one. Use flush and write when ready for a completely new buffer.

Parameters
[in]dataUncompressed input data
[in]lenNumber of bytes to write
Returns
Number of bytes written

The documentation for this class was generated from the following file: