1636
|
1 function X = record (sec, sampling_rate) |
|
2 |
|
3 # usage: X = record (sec [, sampling_rate]) |
|
4 # |
|
5 # Records sec seconds of audio into the vector X. |
|
6 # The default value for the sampling_rate is 8000, ie. 8kHz. |
|
7 # The program waits for you to hit the ENTER key, then the recording |
|
8 # starts immediatly. |
|
9 |
|
10 # Written by AW (Andreas.Weingessel@ci.tuwien.ac.at) on Sep 19, 1994 |
|
11 # Last modified by AW on Oct 5, 1994 |
|
12 # Copyright Dept of Probability Theory and Statistics TU Wien |
|
13 |
|
14 if (nargin == 1) |
|
15 sampling_rate = 8000; |
|
16 elseif (nargin != 2) |
|
17 usage ("X = record (sec [, sampling_rate])"); |
|
18 endif |
|
19 |
|
20 file = octave_tmp_file_name (); |
|
21 |
|
22 input ("Please hit ENTER and speak afterwards!\n", 1); |
|
23 |
|
24 cmd = sprintf ("dd if=/dev/dsp of=%s bs=%d count=%d", |
|
25 file, sampling_rate, sec) |
|
26 |
|
27 system (cmd); |
|
28 |
|
29 num = fopen (file, "r"); |
|
30 |
|
31 [Y, c] = fread (num, sampling_rate * sec, "uchar"); |
|
32 |
|
33 fclose (num); |
|
34 |
|
35 unlink (file); |
|
36 |
|
37 X = Y - 127; |
|
38 |
|
39 endfunction |