- https://www.mathworks.com/help/matlab/ref/sound.html
- https://www.mathworks.com/help/matlab/ref/audiodevinfo.html
Error using sound function
64 次查看(过去 30 天)
显示 更早的评论
I'm have an odd issue with a function I'm using for a Matlab App. I've been using this funciton for over a year without any issues and I have not changed it since originally writing it. However, I am now getting an error when I use Matlab 2022b. I get the error when I run the app using the App designer or running the App after the installation in the App tab of Matlab. However, I do not get this error on the same computer when I use Matlab 2020b. I also do not get this error when I install the App on other computers using Matlab 2022b. Does anyone know why this happening?
Thanks
The error:
Error using sound
Device Error: Invalid number of channels
The Function:
function playWarning()
%
persistent warningSoundY
persistent warningSoundFs
if isempty(warningSoundY)
addpath('Assets\Sounds\')
[ warningSoundY, warningSoundFs ] = audioread('chord.wav');
end
sound(warningSoundY, warningSoundFs)
end
0 个评论
采纳的回答
Subhajyoti
2024-11-3,0:06
The error is occurring due to channel support limitation on the system. Stereo playback is available only if your system supports it.
Here, in the following implementation, I have determined the number of channels in a WAV file using the ‘audioread’ function to read the file and then inspect the dimensions of the audio data.
% Read the audio file
[warningSoundY, ~] = audioread(‘chord.wav’);
% Determine the number of channels
numChannels = size(warningSoundY, 2);
% Display the number of channels
disp(['Number of channels in the WAV file: ', num2str(numChannels)]);
You can find if output device supports the sample rate, number of bits per sample, and number of channels specified by the values of ‘Fs’, ‘nBits’, and ‘nChannels’, respectively. If no supporting device is found, then ‘suppDevID’ is -1.
info = audiodevinfo
suppDevID_32 = audiodevinfo(0,44100,32,2)
Refer to the following resources to know sending audio signals to the speaker in MATLAB:
Additionally, you can refer to the following resources to know more about playing audio files in MATLAB:
2 个评论
Star Strider
2024-11-3,6:30
‘The error is occurring due to channel support limitation on the system. Stereo playback is available only if your system supports it.’
That is the essence of this problem. The audiodevinfo functiion is the only function that can address this issue, annd it does not return that information.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!