20-5 ���T���g��

§Ú­Ì¤]¥i¥H¸g¥Ñ MATLAB ±N­µ°T¸ê®Æª½±µÀx¦s¬°­µ°TÀɮסA¥H«K¤é«áª½±µ¦b¹q¸£¼½©ñ¡A¦Ó¤£»Ý¨C¦¸³£¸g¥Ñ MATLAB ¼½©ñ¡C¼g¤J­µ°TÀɮתº«ü¥O¬O audiowrite¡A¥Îªk¦p¤U¡G

audiowrite(audioFile, y, fs)

¨ä¤¤ audioFile «h¬O±ý¼g¤J¸ê®ÆªºÀɮצWºÙ¡Ay ¬O­µ°TÅܼơAfs ¬O¨ú¼ËÀW²v¡C¨Ò¦p¡A­Y­n±NÁú¼wº¸ªººq¼@¿ý­µ¦s¤J handel.wav¡A¥i¥Î¤U¦Cµ{¦¡½X¡G

Example 1: 20-­µ°TŪ¼g¡B¿ý»s»P¼½©ñ/audioWrite01.mload handel.mat audioFile='handel.wav'; % ±ýÀx¦sªº wav ÀÉ®× fprintf('Saving to %s...\n', audioFile); audiowrite(audioFile, y, round(1.5*Fs)); %fprintf('«ö¥ô·NÁä«á¶}©l¼½©ñ %s...\n', audioFile); pause system(audioFile); % ¶}±Ò»P wav ÀÉ®×¹ïÀ³ªºÀ³¥Îµ{¦¡Saving to handel.wav...

¦b¤W¨Ò¤¤¡A§Ú­Ì±N­µ°T¸ê®ÆÀx¦s¦Ü handel.wav¡A¨Ã¥Î¹q¸£¹ïÀ³ªºªºÀ³¥Îµ{¦¡¨Ó¼½©ñ¦¹ wav ÀɮסC

¥Ø«e¦bMATLAB 8 ª©¡Aaudiowrite «ü¥O©Ò¤ä´©ªº¿é¥X­µ°TÀÉ®×¥]§t WAVE (.wav)¡BOGG (.ogg)¡BFLAC (.flac)¡BMPEG-4 AAC (.m4a & .mp4)¡C

Hint
¦pªG§A¥u¥Î MATLAB ¶i¦æ­µ°T¿ý»s»P¼½©ñ¡A¨º»ò´N¥i¥Hª½±µ¨Ï¥Î save «ü¥O±N­µ°TÅܼÆÀx¦s¦¨ mat ÀɮסA¦A¥Î load «ü¥O¸ü¤J¡A¤]´N°÷¥Î¤F¡A³o®É­Ô´N¤£¥²¥Î¨ì wavwrite¡Bauwrite µ¥«ü¥O¤F¡C

¥H¤U½d¨Ò¾ã¦X¿ý­µ¡B¼½©ñ¡B¦sÀÉ©ó¦P¤@¥÷µ{¦¡½X¡G

Example 2: 20-­µ°TŪ¼g¡B¿ý»s»P¼½©ñ/audioWrite02.mfs=16000; % ¨ú¼ËÀW²v nBits=16; % ¨ú¼ËÂI¸ÑªR«×¡A¥²¶·¬O 8 ©Î 16 ©Î 24 nChannel=1; % Án¹D­Ó¼Æ¡A¥²¶·¬O 1¡]³æÁn¹D¡^ ©Î 2¡]ÂùÁn¹D©Î¥ßÅé­µ¡^ duration=3; % ¿ý­µ®É¶¡¡]¬í¡^ recObj=audiorecorder(fs, nBits, nChannel); fprintf('«ö¥ô·NÁä«á¶}©l %g ¬í¿ý­µ¡G', duration); pause fprintf('¿ý­µ¤¤...'); recordblocking(recObj, duration); fprintf('¿ý­µµ²§ô\n'); fprintf('«ö¥ô·NÁä«á¶}©l¼½©ñ¡G\n'); pause y = getaudiodata(recObj, 'double'); % get data as a double array plot((1:length(data))/fs, y); xlabel('Time (sec)'); ylabel('Amplitude'); sound(y, fs); audioFile='myRecording.wav'; % ±ýÀx¦sªº wav ÀÉ®× fprintf('Saving to %s...\n', audioFile); audiowrite(audioFile, y, fs); system(audioFile); % ¶}±Ò»P wav ÀÉ®×¹ïÀ³ªºÀ³¥Îµ{¦¡«ö¥ô·NÁä«á¶}©l 3 ¬í¿ý­µ¡G¿ý­µ¤¤...¿ý­µµ²§ô «ö¥ô·NÁä«á¶}©l¼½©ñ¡G Saving to myRecording.wav...


MATLABµ{¦¡³]­p¡G¤Jªù½g