How to resolve "Invalid sample rate" error when using audioPlayerRecorder
79 ビュー (過去 30 日間)
古いコメントを表示
I want to play & record synchronously but this code fails.
Perhaps the error is caused because a driver is not installed or Windows device parameters are not set appropriately.
Forgive the longish progam; I'm not sure how much context is needed for a specific diagnosis.
% PR_trouble.m Matlab 2019b(9.9.0.1467703) 3.6GHz i9 Dell Win10 PC
clear; close all force; clc;
% Make & verify a wav file
file_name = 'soundfile.wav';
fullfile_name = fullfile ( pwd, file_name );
fs = 44100;
tone = sin ( 2 * pi * 1000 * (1:51200)/fs );
audiowrite ( fullfile_name, tone, fs );
wav_file_info = audioinfo ( fullfile_name )
% Make AudioFileReader, AudioFileWriter & audioPlayerRecorder
my_Reader = dsp.AudioFileReader ...
( fullfile_name, 'SamplesPerFrame',512 );
fs = my_Reader.SampleRate
my_Writer = dsp.AudioFileWriter ...
( fullfile(pwd,'output.wav'), 'SampleRate',fs )
available_playRecs = audioPlayerRecorder
my_aPR = audioPlayerRecorder ( 'SampleRate', fs );
devices = getAudioDevices ( my_aPR )
% Play & record
while ~ isDone ( my_Reader )
audioToPlay = my_Reader ();
audioRecorded = my_aPR ( audioToPlay ); %%% ERROR HAPPENS HERE -- FIRST EXECUTION
my_Writer ( audioRecorded );
end
wav_file_info =
struct with fields:
Filename: 'C:\Users\psycuser\Desktop\MatlabPrograms\native_egg_sound\soundfile.wav'
CompressionMethod: 'Uncompressed'
NumChannels: 1
SampleRate: 44100
TotalSamples: 51200
Duration: 1.160997732426304
BitsPerSample: 16
fs =
44100
my_Writer =
dsp.AudioFileWriter with properties:
Filename: 'C:\Users\psycuser\Desktop\MatlabPrograms\native_egg_sound\output.wav'
FileFormat: 'WAV'
SampleRate: 44100
Compressor: 'None (uncompressed)'
DataType: 'int16'
available_playRecs =
audioPlayerRecorder with properties:
Device: 'Default'
SampleRate: 44100
devices =
1×2 cell array
{'Default'} {'Realtek ASIO'}
Error using audioDeviceReader/setup
PortAudio Error: Unanticipated host error
Error using audioDeviceReader/setup
PortAudio Error: Invalid sample rate
Error in audioDeviceReader/setupImpl
Error in audioPlayerRecorder/setupImpl
Error in PR_trouble (line 31)
audioRecorded = my_aPR ( audioToPlay ); - Show complete stack trace
0 件のコメント
回答 (1 件)
Saurav Chaudhary
2020 年 10 月 30 日
As can be seen the first error you get is :
PortAudio Error: Unanticipated host error
Go through the following MATLAB answer which aims at resolving this issue-
The next error you are getting is :
PortAudio Error: Invalid sample rate
For this one workaround would be to look at the maximum sample rate supported, you can go through the below MATLAB answer to find out about this -
Hope, this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!