arduino simple tts
October 2024 - Many Changes
微控制器没有足够的资源来提供高质量的“文本到语音”功能。但是,通常可能足以提供基于一些预录用音频的解决方案。
我想知道这种方法的局限性,并决定实现基于音频输出的Arduino音频工具的小型原型Arduino库。
为了使事情变得简单,我从一个简单的实现开始,该实现可以处理数字,最重要的是,另一个可以读出时间。因此,起点是一些将数字转换为文本的类。然后,该文本用于标识预录的音频文件。
该功能可用于构建一些功能
numberTotext将数字输入转换为audio_tools ::单词向量。在以下示例中,我们只将它们打印出来:
NumberToText ntt;
auto result = ntt.say( 700123.431 );
for ( auto str : result){
Serial. print (str);
Serial. print ( " " );
}
结果是:七十万二十三个点三个三个零零零
处理您需要提供小时和小时作为输入的时间。
TimeToText ttt;
auto result = ttt.say( 12 , 00 );
for ( auto str : result){
Serial. print (str);
Serial. print ( " " );
}
结果是:中午
您还可以使用相应的单元处理数字
NumberUnitToText utt;
auto result = utt.say( 1.01 , " usd " );
for ( auto str : result){
Serial. print (str);
Serial. print ( " " );
}
结果是:一美元和一分钱
如果我们在mp3中记录单词,我们甚至可能会逃离需要单独的SD驱动器,因为我们可以将音频存储在程序内存中。 extepleaudiodictionaryValues包含存储在ProgMem中的已记录的MP3文件。
# include " SimpleTTS.h "
# include " AudioTools/AudioCodecs/CodecMP3Helix.h "
I2SStream i2s; // audio output via I2S
MP3DecoderHelix mp3; // mp3 decoder
AudioDictionary dictionary (ExampleAudioDictionaryValues);
TextToSpeech tts (i2s, mp3, dictionary);
void setup (){
Serial. begin ( 115200 );
// setup i2s
auto cfg = i2s. defaultConfig ();
cfg. sample_rate = 24000 ;
cfg. channels = 1 ;
i2s. begin (cfg);
tts. say ( " BILLION " );
}
void loop () {
}
“十亿”一词是通过i2s说出来的。
您还可以使用上述文本生成类:
# include " SimpleTTS.h "
# include " AudioTools/AudioCodecs/CodecMP3Helix.h "
TimeToText ttt; // Text source
I2SStream i2s; // audio output via I2S
MP3DecoderHelix mp3; // mp3 decoder
AudioDictionary dictionary (ExampleAudioDictionaryValues);
TextToSpeech tts (ttt, i2s, mp3, dictionary);
void setup (){
Serial. begin ( 115200 );
// setup i2s
auto cfg = i2s. defaultConfig ();
cfg. sample_rate = 24000 ;
cfg. channels = 1 ;
i2s. begin (cfg);
ttt. say ( 14 , 40 );
}
void loop () {
}
这将通过i2s输出音频结果。
这是提供说话时间和数字支持的草图的信息,并将所有音频文件作为mp3中的所有音频文件存储在progmem on as eSP32上:
Sketch uses 740438 bytes (23%) of program storage space. Maximum is 3145728 bytes.
Global variables use 23632 bytes (7%) of dynamic memory, leaving 304048 bytes for
我认为这留下了足够的净空,您仍然可以选择将音频存储在SD驱动器上...
这是指向生成的类文档的链接。可以在Wiki和我的博客中找到更多信息