Just gave this a very quick try... Downloaded some WAV files of someone saying numbers - and converted them to 4kHz unsigned 8 bit raw files with sox 0.wav -r 4k -b 8 -c 1 -e unsigned-integer 0.raw vol 2 (on linux - but you could just use Audacity) and uploaded them using the Web IDE's storage menu.
Then ran this:
function play(txt, callback) {
function playChar(txt) {
if (txt.length==0) {
digitalWrite(D18,0);
if (callback) callback();
return;
}
var c = txt[0];
var s = require("Storage").read(c+".raw");
var w = new Waveform(s.length);
w.buffer.set(s);
w.startOutput(D18, 4000);
w.on("finish", function(buf) {
playChar(txt.substr(1));
});
}
analogWrite(D18, 0.5, {freq:40000});
playChar(txt);
}
play("012"); // says 'zero' 'one' 'two'
Definitely works ok, although not loud.
Without a speaker it's more of a pain since you have to scale the output values so they're not high enough to move the vibration motor:
function play(txt, callback) {
function playChar(txt) {
if (txt.length==0) {
digitalWrite(D18,0);
if (callback) callback();
return;
}
var c = txt[0];
var s = require("Storage").read(c+".raw");
var w = new Waveform(s.length);
var b = w.buffer;
b.set(s);
for (var i=s.length-1;i>=0;i--)b[i]/=4;
w.startOutput(VIBRATE, 4000);
w.on("finish", function(buf) {
playChar(txt.substr(1));
});
}
analogWrite(VIBRATE, 0.1, {freq:40000});
playChar(txt);
}
But that could actually be done before the files are even written to flash
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Just gave this a very quick try... Downloaded some WAV files of someone saying numbers - and converted them to 4kHz unsigned 8 bit raw files with
sox 0.wav -r 4k -b 8 -c 1 -e unsigned-integer 0.raw vol 2
(on linux - but you could just use Audacity) and uploaded them using the Web IDE's storage menu.Then ran this:
Definitely works ok, although not loud.
Without a speaker it's more of a pain since you have to scale the output values so they're not high enough to move the vibration motor:
But that could actually be done before the files are even written to flash