- https://www.mathworks.com/help/matlab/ref/sound.html
- https://www.mathworks.com/help/matlab/ref/audiodevinfo.html
Error using sound function
조회 수: 66 (최근 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!