clear all
% WAV file produced by the very good ATT text-to-speech utility
% http://www2.research.att.com/~ttsweb/tts/demo.php
[s, Fs] = wavread('Z:\Matlab\476\speech\Mike_digits_16khz.WAV');
%OPTIONAL !! drop the sample rate to 8 kHz IF you can.
% I find with numeric digits "six" is not clear
% at 8 kHz
s = resample(s,1,2);
Fs = 8000;
figure(1)
subplot(2,1,1)
spectrogram(s,256,100,256,Fs, 'yaxis')
% now scale to 0-to-15 for the 4-bit DAC
min_s = min(s);
max_s = max(s);
s = s - min_s;
s = fix(s * (15.5/(max_s-min_s)));
subplot(2,1,2)
[b,a] = butter(1,1600/4000); %10,000 rad/sec
s = filter(b,a,s);
spectrogram(s,256,100,256,Fs, 'yaxis')
j=1;
return
% and byte pack the codes
for i = 1:2:length(s)-1
packed(j) = s(i) + 16*s(i+1); % low order is first sample
j = j + 1;
end
%make a textfile with PIC XC32 source code in it.
fname='Mike_digits_8khz_packed.h';
fid = fopen(fname,'w');
%static constant means to store it in flash
fprintf(fid,'static const unsigned char AllDigits[]={\r');
for i=1:length(packed)-1
fprintf(fid,' %5d,\r',packed(i));
end
fprintf(fid,' %5d};\r',packed(end));
fclose(fid);