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和我的博客中找到更多信息