16 #include "sam_arduino_out.h"
46 SAM_LOG(
"SAM callback");
52 SAM(Print &stream,
bool as_text=
false){
53 SAM_LOG(
"SAM Stream");
64 SAM_LOG(
"SAM SAMOutputBase");
71 SAM_LOG(
"SAM SAMOutputBase");
76 #if defined(ESP32) && LEGACY_ESP_I2S
78 SAM(i2s_port_t i2s_num){
94 void setPitch(uint8_t pitch) {
98 void setSpeed(uint8_t speed) {
102 void setMouth(uint8_t mouth) {
106 void setThroat(uint8_t th) {
110 void setSingMode(
bool sing){
111 EnableSingmode(sing);
125 SAM_LOG(
"setVoice: %d", voice);
151 case ExtraTerrestrial:
167 bool say(
const char* text){
168 SAM_LOG(
"say: %s",text);
169 return textToSpeach(text,
false);
174 SAM_LOG(
"sayPhone: %s",text);
175 return textToSpeach(text,
true);
180 return arduino_output;
186 if(arduino_output!=
nullptr && arduino_output->isOpen()){
187 arduino_output->close();
193 SAM_LOG(
"setOutputChannels: %d", channel_count);
194 if (channel_count > 0){
196 this->channel_count = channel_count;
197 arduino_output->setChannels(channel_count);
199 SAM_LOG(
"Channels is not supported for this output type");
206 return SAMOutputBase::sampleRate();
211 return bits_per_sample;
216 return channel_count;
221 volume =
static_cast<float>(volPercent) / 100.0;
222 if (volPercent> 100) volume = 1.0;
227 int bits_per_sample = 16;
228 int channel_count = 1;
233 SAM_LOG(
"outputByteCallback: %d", b);
235 SAM *sam =
static_cast<SAM*
>(cbdata);
240 SAM_LOG(
"setOutput");
241 arduino_output = out;
244 if (arduino_output->channels()!=-1){
245 this->channel_count = arduino_output->channels();
247 arduino_output->setChannels(channel_count);
249 SAM_LOG(
"-> channel_count: %d",this->channel_count);
250 SAM_LOG(
"-> bits_per_sample: %d",this->bits_per_sample);
255 SAM_LOG(
"SAM::write bps:%d / channels:%d",bits_per_sample, channel_count);
256 int16_t data[channel_count];
262 sample = sample * volume;
264 for (
int j = 0; j<channel_count; j++){
267 arduino_output->write((
byte*)data,
sizeof(data));
271 bool textToSpeach(
const char *str,
bool is_phonetic) {
272 SAM_LOG(
"textToSpeach: %s",str);
274 if (!str || strlen(str)>254)
return false;
275 samdata =
new SamData();
276 if (samdata ==
nullptr){
280 arduino_output->open();
284 for (
int i=0; str[i]; i++)
285 input[i] = toupper((
int)str[i]);
286 input[strlen(str)] = 0;
287 SAM_LOG(
"input copied");
291 strncat(input,
"\x9b", 255);
293 SAM_LOG(
"TextToPhonemes");
294 strncat(input,
"[", 255);
295 if (!TextToPhonemes(input))
return false;
298 SAM_LOG(
"SetInput: %s", input);
303 SAM_LOG(
"SAMMain - done");
306 SAM_LOG(
"SAM done!");
307 arduino_output->close();
316 void printLog(
char* msg){
Arduino API for SAM Text to Speach Engine.
Definition: sam_arduino.h:24
SAM()
Constructor - for text output to Serial.
Definition: sam_arduino.h:38
void setOutputChannels(int channel_count)
Defines the number of output channels (default 1)
Definition: sam_arduino.h:192
~SAM()
Destroy the SAM object.
Definition: sam_arduino.h:89
static void outputByteCallback(void *cbdata, unsigned char b)
Used to feed the audio result back to this class.
Definition: sam_arduino.h:232
void setVoice(Voice voice)
Set the Voice object DESCRIPTION SPEED PITCH THROAT MOUTH Elf 72 64 110 160 Little Robot 92 60 190 19...
Definition: sam_arduino.h:124
SAM(i2s_port_t i2s_num)
Deactivated: Legacy Constructor - for obsolete ESP32 I2S.
Definition: sam_arduino.h:78
SAMOutputBase * getOutput()
provides access to output information
Definition: sam_arduino.h:179
void write(uint8_t in)
Writes the data to the output. The data is provided on 1 channel as unsinged byte of int16 values.
Definition: sam_arduino.h:254
bool say(const char *text)
Process text input.
Definition: sam_arduino.h:167
SAM(SAMOutputBase &out)
Constructor - for output with a SAMOutputBase class.
Definition: sam_arduino.h:63
bool sayPhone(const char *text)
Process text input.
Definition: sam_arduino.h:173
void end()
Delete voice and cst_audio_streaming_info.
Definition: sam_arduino.h:184
SAM(sam_callback cb)
Constructor - for output to callback.
Definition: sam_arduino.h:45
SAM(Print &stream, bool as_text=false)
Constructor - for output to a stream.
Definition: sam_arduino.h:52
SAM(SAMOutputBase *out)
Constructor - for output with a SAMOutputBase class.
Definition: sam_arduino.h:70
static int sampleRate()
Provides the sample rate (44100)
Definition: sam_arduino.h:205
int channels()
Provides the number of channels.
Definition: sam_arduino.h:215
void setVolume(uint8_t volPercent)
set the Volume range 0-100;
Definition: sam_arduino.h:220
Voice
SAM Voices.
Definition: sam_arduino.h:28
int bitsPerSample()
Provides the bits per sample.
Definition: sam_arduino.h:210
Base Output Class with common functionality.
Definition: sam_arduino_out.h:32
Output via Callback method.
Definition: sam_arduino_out.h:78
Output to I2S for ESP32: This class is obsolete and has been deactivated in the sam_config....
Definition: sam_arduino_out.h:116
Output to Arduino Stream.
Definition: sam_arduino_out.h:248
Write readable string to Arduino Stream.
Definition: sam_arduino_out.h:276
string and pitch - this can be used to build a song
Definition: sam_arduino.h:324