Vous êtes sur la page 1sur 27

MATLABFunctionalityforDigital SpeechProcessing

MATLABSpeechProcessingCode MATLABGUIImplementations

Lecture_3_2012

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)
2

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 isscaledtorange32768xin32767 [xin1,fs,nbits]=wavread(s5.wav); [xin2,fs]=loadwav(s5.wav);
3

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

HelloWorld GUI25

GUI25InitialScreen

GUI25EditScreen

Play/PlotExistingSpeechFile
Play_Plot_Speech_GUI25.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 scaledtotherange32768xout32767 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

10

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;

11

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
12

PlayMultipleSpeechFiles
test_play_files.m
playthefollowingsequenceoffiles:

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


13

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

14

RecordSpeechintoMATLABArray
record_display_speech_GUI25.m

15

PlotSpeechUsingStripsPlot

16

PlotSpeechUsingStripsPlot
strips_plot_GUI25.m

17

PlotSpeechUsing4LinePlot

18

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);
19

SampleRateConversion
SRC_GUI25.m

20

FilterSpeechWaveform

21

FilterSpeechWaveform
filter_GUI25.m

22

PlotSignalandSTFTLogMagnitude

23

MultipleSpectraGUI
multiple_spectra_GUI25.m

24

PlotSpectrogram

25

PlotSpectrogram
spectrogram_GUI25.m

26

PlotMultipleSpectrograms

27

Vous aimerez peut-être aussi