audiowrite audio file create

I should create an audio file with audiowrite, to save the same sound I can hear with sound function. How should I set function parameters?
% code
load flux_adaptive_100
filename = 'flux_adaptive_100.wav';
audiowrite (filename,y,Fs);
clear y Fs
end

10 Kommentare

Image Analyst
Image Analyst am 26 Nov. 2015
What parameters? You already have y and Fs when you played the sound in the sound function, and you're specifying the filename, so what additional parameters do you think you need for audiowrite()?
Marco  Cornero
Marco Cornero am 26 Nov. 2015
sorry, i mean variables: in particular y and Fs. I tried to use the same Fs of sound function. My input matrix is 200000x1 double. I want to obtain a 2 seconds file. Thanks
Geoff Hayes
Geoff Hayes am 26 Nov. 2015
Bearbeitet: Geoff Hayes am 26 Nov. 2015
According to audiowrite, you are passing the correct parameters into the function call.
You mention a two second file...is that the first two seconds, or last two, or is your audio data just two seconds in length?
If you want the first two seconds, then you would do something like
audiowrite (filename,y(1:2*Fs),Fs);
assuming Fs is the number of samples per second and 2*Fs is less than 200000.
Marco  Cornero
Marco Cornero am 26 Nov. 2015
I sampled a signal with a 1e-5 sample rate, which gave me the matrix I described before. If I choose Fs=100000 shouldn't be the file length = 2 seconds?
Using simple words: i want to save the sound i can hear using
sound(flux_adaptive_100,100000)
which is a 2 seconds length audio.
If Fs is 100000 and your y is of length 200000, then it is two seconds in length. So
audiowrite (filename,y,Fs);
is correct. Or are you saying that this doesn't work?
I'm saying that this doesn't work: now the length of the file is correct but there isn't any sound, while using
sound(flux_adaptive_100,100000)
the sound is hearable
Geoff Hayes
Geoff Hayes am 26 Nov. 2015
Okay. What are the units of y? You mention how y is an array of doubles, so what is the minimum and what is the maximum? What happens when you read the flux_adaptive_100.wav back into MATLAB? Can you hear any audio once you start playing it? If not, then check the samples and compare to those that you saved to file (what is the minimum and what is the maximum?).
Marco  Cornero
Marco Cornero am 26 Nov. 2015
if I open in matlab flux_adaptive_100.wav I obtain a column with constant value = 1
Marco  Cornero
Marco Cornero am 26 Nov. 2015
I found the solution!!! I had to write y=flux_adaptive_100(:,1)

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 26 Nov. 2015

Kommentiert:

am 26 Nov. 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by