I've been searching the forums and web and I want to make sure I'm not missing something.
I'm building a very simple book reader.
I want to be able to use the .tell() function to track progress in the book
In the even the reader loses power; I want the book reader to pick up where it left off by seeking to the position based on the last .tell() call - that will be written to a file on an SD card.
Hardware (current):
* qtpy ESP 32 Pico
* Micro SD BFF
* Adafruit I2S 3W Class D Amplifier Breakout - MAX98357A
I can get the wave file to play with this code:
Code: Select all
wav = open(wave_file, "rb")
wave = WaveFile(wav)
audio.play(wave)
Code: Select all
wav = open(wave_file, "rb")
wav.seek(seek_position)
wave = WaveFile(wav)
audio.play(wave)
if I try to remove audiocore.WaveFile:
Code: Select all
wav = open(wave_file, "rb")
wav.seek(seek_position)
audio.play(wav)
If I try to use the adafruit_wave library:
Code: Select all
wav = adafruit_wave.open(wave_file, "rb")
wave = WavFile(wav)
audio.play(wave)
So far the only success I've had is to open the primary wave file, seek to a position in it, then write the remainder to a temporary file on the SD card then open that for reading.
Code: Select all
in_wav_file = adafruit_wave.open(wav_file, 'rb')
out_wav_file = adafruit_wave.open(tmp_file, 'wb')
in_wav_file.setpos(seek_position)
out_wav_file.setframerate(in_wav_file.getframerate())
out_wav_file.setnchannels(in_wav_file.getnchannels())
out_wav_file.setsampwidth(in_wav_file.getsampwidth())
frame_rate = in_wav_file.getframerate()
frames_to_read = int(frame_rate*bytes_read)
while frames_to_read > 0:
chunk_size = min(frame_rate, frames_to_read)
out_wav_file.writeframes(in_wav_file.readframes(chunk_size))
frames_to_read -= chunk_size
frames = in_wav_file.readframes(frame_rate)
out_wav_file.writeframes(frames)
in_wav_file.close()
out_wav_file.close()
Can someone help me understand what I'm doing wrong when trying to use the seek() function or the adafruit_wave library?
Thanks,
Nicole