ESP32 Spiffs/ Audio Tools integration #1050
-
I'm looking at your Audio Tools library with a view to using it to replace the WAV file player in a speaking clock project https://forum.arduino.cc/t/arduino-esp8266-speaking-clock/537958 I wrote about 5 years ago which currently runs on an ESP8266 and I am moving it to an ESP32 (ESP32-C3 subject to compatibility). I am now wondering what the best approach is. At the moment it works like this. The audio is encoded as 16 bit mono WAV and is contained in a single spiffs file. A work flow runs and picks the appropriate "track" to play at a specific time. Each track contains a number (say "eleven") or a phrase (say "it will be") and is identified by its position and length within the spiffs file. The "track" is found using an index file and the spiffs seek() method and loaded in (max) 128 byte chunks into a set of buffers which are in turn fed into the I2S DMA buffer using the apparently no longer supported i2s_write_sample_nb() method. Once a track has ended, the buffers are fed with audio silence until the next track is ready. I see a number of options but the one I am now currently interested in is integrating your player instead of my home made solution and one reason is because I2S seems to be quite prone to breaking changes between releases and I want to isolate the code from that as far as possible. I should be grateful if you could just point me in the right direction integrating spiffs with the WAV player in the simplest manner. I could guess a starting point would be variant of the MemoryStream class where I could keep adding chunks from the spiffs file then follow the examples of the I2SStream and StreamCopy class but maybe there is a more direct way? Many thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
I suggest that you have a look at this project... |
Beta Was this translation helpful? Give feedback.
-
SPIFFS files are streams, so you can use them directly in StreamCopy. |
Beta Was this translation helpful? Give feedback.
-
OK. Thanks for looking at this. I've solved this in the mean time in a quick and dirty way using the legacy i2s class in the ESP32 Arduino 2.0.14 development environment. It works but I am not very happy with it because even the published example code generates streams of compiler warnings. It is also clear that big changes to I2S are coming with the 3.x.x so I'll wait to see what emerges there before reviewing the solution again. I could not see a way to use your player directly because, although of course complete spiffs files can be treated as streams, I am picking selected parts out a single file using seek which I hand over to the player in whatever chunks [it] the player can accept. This is, incidentally, different to your Text to Speech concept of having a large number of discrete files, one for each sound item and, at this stage, I don't want a major design change. |
Beta Was this translation helpful? Give feedback.
-
I wouln't have used the player for this case either, because I don't see that it provides any added value. In your case I would have just used your audio files converted to progmem and copied the relevant parts to whatever output device you choose. Or if you want to keep the complexity of files do the same thing with them... There is a prerelease for 3.0.0 and you can try that out. In any case you can choose to use either my I2SStream or the solution provided by Arduino which is based on a Stream as well... I was considering your approach for a short time as well, but rejected it because it does not work properly with any codec |
Beta Was this translation helpful? Give feedback.
I suggest that you have a look at this project...