数学建模社区-数学中国
标题:
matlab怎么提取音频
[打印本页]
作者:
﹏便是晴天ヾ
时间:
2013-11-6 21:05
标题:
matlab怎么提取音频
matlab怎么提取音频
作者:
madio
时间:
2013-11-7 10:11
使用wavread
+ ~' M/ L$ J2 n6 ]/ \
Create a WAV file from the example file handel.mat,
, M/ U: R5 l8 B+ ^
and read portions of the file back into MATLAB.% Create WAV file in current folder.
! {: N* l6 t3 U! F" V' h
load handel.mat
% M' Y. j) h# G& X
* Q. |* {1 N# e* s! i0 @
hfile = 'handel.wav';
7 J6 m! R6 d g4 ^
wavwrite(y, Fs, hfile)
! s& R8 f% ]7 S- [% ^- W! d3 K9 l
clear y Fs
1 v# }4 k1 y9 B2 d- s
9 K7 `2 U) V- ] p7 I
% Read the data back into MATLAB, and listen to audio.
4 h( E! l$ I. S! n7 w0 E. N
[y, Fs, nbits, readinfo] = wavread(hfile);
' [) F! I3 }: a3 {
sound(y, Fs);
2 S. I; N' z5 G& _9 e
5 q1 U' o/ Q# v6 x) l
% Pause before next read and playback operation.
6 k* F" O$ I; Q7 t9 d, e) T _
duration = numel(y) / Fs;
/ {( X, P& Q! @; T& T2 u) l
pause(duration + 2)
2 r6 d: r0 k& p# K9 ^
5 {2 l) s' j ?: `9 c& X* c# E$ K( ~
% Read and play only the first 2 seconds.
_: [2 d1 U" `- @- w
nsamples = 2 * Fs;
! p3 |' q- [ x4 G v
[y2, Fs] = wavread(hfile, nsamples);
( X# V5 f8 f1 T; O
sound(y2, Fs);
' p- G8 F: q' g( F; r' D
pause(4)
0 b8 O: R7 W* C0 K
: x& R! t1 f8 w
% Read and play the middle third of the file.
6 Y/ H9 R7 v3 k& n
sizeinfo = wavread(hfile, 'size');
! Y5 w# j, ]1 h1 l
8 `# c2 R* N1 M6 }
tot_samples = sizeinfo(1);
9 B. y4 |! F8 [3 K$ E; l
startpos = tot_samples / 3;
5 \9 k. \ {+ U5 F
endpos = 2 * startpos;
4 h: Y" r: r" W/ U
+ P5 L8 V8 d2 Z" D$ V S0 ^
[y3, Fs] = wavread(hfile, [startpos endpos]);
0 o9 \3 B+ h$ u/ r. t! T- F$ E
sound(y3, Fs);
作者:
陌上,烟雨遥
时间:
2013-12-12 09:54
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5