Reputation: 1
I have a 6467584*1 double array containing audio data. The sampling frequency for the data is 256. When I try to play the audio using the soundsc
function it shows the following error :
Error using sound (line 76) Device Error: Invalid sample rate. Error in soundsc (line 55)
sound(varargin{:});
Is there any function that I can use in MATLAB to play audio?
Upvotes: 0
Views: 3866
Reputation: 2927
If you look into documentation of soundsc
:
Fs: Sample rate, in hertz, of audio data y, is specified as a positive number from 1000 through 384000. Valid values depend on both the sample rates permitted by MATLAB® and the specific audio hardware on your system. MATLAB has a hard restriction of 1000 Hz <= Fs <= 384000 Hz, although further hardware-dependent restrictions apply.
It's not strange then that with sampling frequency of 256Hz you get the error...
Use one of the sampling frequencies supported by your sound card. Available devices and sampling frequencies which they support can be checked using function audiodevinfo
.
When frequency at which your data was sampled doesn't match any of sampling frequencies supported by your sound card, you need to (up/down)sample it to have it played with the "correct" speed and pitch.
audiosc
:audio
which is basically the same as audiosc
but doesn't scale/normalize your dataaudioplayer
Upvotes: 1