Vous êtes sur la page 1sur 25

MATLABFunctionalityforDigital

SpeechProcessing
MATLABSpeechProcessingCode
MATLABGUIImplementations

BasicFunctionality

readaspeechfile(i.e.,opena.wavspeechfileandreadthespeechsampleintoa
MATLABarray)
writeaspeechfile(i.e.,writeaMATLABarrayofspeechsamplesintoa.wav
speechfile)
playaMATLABarrayofspeechsamplesasanaudiofile
playasequenceofMATLABarraysofspeechsamplesasasequenceofaudiofiles
recordaspeechfileintoaMATLABarray
plotaspeechfile(MATLABarray)asawaveformusingastripsplotformat
plotaspeechfile(MATLABarray)asoneormore4lineplot(s)
convertthesamplingrateassociatedwithaspeechfile(MATLABarray)toa
differentsamplingrate
highpass filteraspeechfile(MATLABarray)toeliminatehumandlowfrequency
noise
plotaframeofspeechanditsassociatedspectrallogmagnitude
plotaspectrogramofaspeechfile(MATLABarray)
plotmultiplespectrogramsofoneormorespeechfiles(MATLABarrays)

ReadaSpeechFileintoaMATLAB
Array

[xin,fs,nbits]=wavread(filename);
[xin,fs]=loadwav(filename);
filenameisascii textfora.wavencodedfilewhichcontainsaspeech
signalencodedusinga16bitintegerformat
xin istheMATLABarrayinwhichthespeechsamplesarestored(in
doubleprecisionformat)
fs isthesamplingrateoftheinputspeechsignal
nbits isthenumberofbitsinwhicheachspeechsampleisencoded
(16inmostcases)
programwavread scalesthespeecharray,xin,torange1xin1,
whereasloadwav preservessamplevaluesofthespeechfileand
hencearrayxin isscaledtorange32767xin32767
[xin1,fs,nbits]=wavread(s5.wav);
[xin2,fs]=loadwav(s5.wav);

ReadaSpeechFileintoaMATLABArray

%test_wavread.m
%testwaveread function
%
%readspeechsamplesfromfile'test_16k.wav'intoarrayx1usingwavread
%routine
filein='test_16k.wav';
[x1,fs1,nbits]=wavread(filein);
%printoutvaluesoffs1,nbits,wavmin1,wavmax1
wavmin1=min(x1);
wavmax1=max(x1);
fprintf('file:%s,wavmin/wavmax:%6.2f%6.2f,fs1:%d,nbits:%d\n,
filein,wavmin1,wavmax1,fs1,nbits);
%readspeechsamplesfromsamefileintoarrayx2usingloadwav routine
[x2,fs2]=loadwav(filein);
%printoutvaluesoffs2,nbits,wavmin2,wavmax2
wavmin2=min(x2);
wavmax2=max(x2);
fprintf('file:%s,wavmin/wavmax:%d%d,fs2:%d\n',...
filein,wavmin2,wavmax2,fs2);
TerminalDisplay:
file:test_16k.wav,wavmin/wavmax:1.001.00,fs1:16000,nbits:16
file:test_16k.wav,wavmin/wavmax:3276832767,fs2:16000

Play/PlotExistingSpeechFile
Play_Plot_Speech_GUI.m
MATLABGUIforbasicoperationsofreadingina
file,playingthespeecharray,andplottingthe
speechwaveform

WriteaSpeechArrayintoaSpeech
File

wavwrite(xout,fs,nbits,filename);
savewav(xout,filename,fs);
xout istheMATLABarrayinwhichthespeechsamplesarestored
fs isthesamplingrateoftheoutputspeechsignal
nbits isthenumberofbitsinwhicheachspeechsampleisencoded
filenameistheascii textforthe.wavencodedfileinwhichthe
MATLABsignalarrayistobestored
forwavwrite theMATLABarrayxout needstobescaledtotherange
1xin1whereasforsavewav theMATLABarrayxout needstobe
scaledtotherange32767xout32767
wavwrite(xin1,fs,s5out.1.wav);
savewav(xin2,s5out.2.wav,fs);

WriteaSpeechArrayintoaSpeechFile

%writeoutarrayx1intospeechfileusingwavwrite routine
wavwrite(x1,fs1,nbits,'file1out.wav');

%writeoutarrayx2intospeechfileusingsavewav routine
savewav(x2,'file2out.wav',fs2);

file1out.wav

file2out.wav

PlayaSpeechFile
sound(x,fs);
soundsc(x,fs);
forsoundthespeecharray,x,mustbescaledtotherange
1x1
forsoundsc anyscalingofthespeecharraycanbeused
fs isthesamplingratefthespeechsignal

[xin,fs]=loadwav(s5.wav);%loadspeechfroms5.wav;
xinn =xin/abs(max(xin));%normalizetorangeof1to1;
sound(xinn,fs);%playoutnormalizedspeechfile;
soundsc(xin,fs);%playoutunnormalized speechfile;

PlayMultipleSpeechFiles
play_multiple_files.m;
sequenceoffilenamesreadinviafilelist,keyboardorfile
search

Exampleofusagetoplayout3speechfilesin
sequence:
kbe=filenameentryviafilelist(2),keyboard(1),orfile
search(0):1;%keyboardchosen
N=numberoffilestobeplayedinagroup:3;%playout3
files
i=1;filename:s1.wav;
i=2;filename:s2.wav;
i=3;filename:s3.wav

PlayMultipleSpeechFiles
test_play_files.m
playthefollowingsequenceoffiles:

Maple_short.wav
s1.wav
beep.wav
test_16k.wav
beep.wav
s2.wav

RecordSpeechintoMATLABArray
record_speech.m (callsMATLABfunction
wavrecord.m)
functiony=record_speech(fs,nsec);
fs:samplingfrequency
nsec:numberofsecondsofrecording
y:speechsamplesarraynormalizedtopeakof
32767

RecordSpeechintoMATLABArray
record_display_speech_GUI.m

PlotSpeechUsingStripsPlot

PlotSpeechUsingStripsPlot
strips_plot_GUI.m

PlotSpeechUsing4LinePlot

SampleRateConversion
y=srconv(x,fsin,fsout);
x:inputspeecharray;
fsin:inputspeechsamplingrate;
fsout:desiredspeechsamplingrate;

Example:
[xin,fsin]=loadwav(s5.wav);%fsin=8000;
fsout =10000;%desiredsamplingrate;
y=srconv(xin,fsin,fsout);

SampleRateConversion
SRC_GUI.m

Highpass FilterSpeechWaveform

Highpass FilterSpeechWaveform

Highpass FilterSpeechWaveform
highpass_filter_GUI.m

PlotSignalandSTFTLogMagnitude

MultipleSpectraGUI
multiple_spectra_GUI.m

PlotSpectrogram

PlotSpectrogram
spectrogram_GUI.m

PlotMultipleSpectrograms

Vous aimerez peut-être aussi