I have made a code which runs on matlab online but shows an error when run on my local pc

조회 수: 4 (최근 30일)
% Parameters for recording
fs = 44100; % Sampling frequency (Hz)
nBits = 16; % Bit depth
nChannels = 1; % Number of channels (1 for mono, 2 for stereo)
duration = 10; % Duration of the recording in seconds
% Create an audiorecorder object
recObj = audiorecorder(fs, nBits, nChannels);
No audio input device found on this system.
% Display message
disp('Recording will start in 3 seconds...');
pause(3); % Wait 3 seconds before starting
disp('Recording now...');
% Start recording
recordblocking(recObj, duration);
disp('Recording completed.');
% Retrieve audio data
audioData = getaudiodata(recObj);
% Save the recorded audio as a .wav file
audiowrite('speech_dft.wav', audioData, fs);
disp('Audio file saved as "speech_dft.wav".');
[y,fs] = audioread("speech_dft.wav");
sound(y,fs)
transcript = speech2text(y,fs)
% Assuming 'transcript' contains the transcribed text
transcript = lower(transcript); % Convert to lowercase to handle case-insensitivity
% Initialize variable x
x = NaN; % Default value (if neither word is found)
% Check if "height" is in the transcript
if contains(transcript, 'height')
x = 1; % Assign 1 if "height" is found
% Check if "travel" is in the transcript
elseif contains(transcript, 'travel')
x = 0; % Assign 0 if "travel" is found
end
% Display the value of x
disp(['Value of x: ', num2str(x)]);
%%output is
%Incorrect number or types of inputs or outputs for function isvalid.
%Error in speech2text
  댓글 수: 3
Anurag
Anurag 2024년 11월 25일
Incorrect number or types of inputs or outputs for function isvalid.
Error in speech2text
Walter Roberson
Walter Roberson 2024년 11월 25일
In R2023b the syntax is
transcript = speech2text(clientObj,audioIn,fs)
where clientObj is returned by speechClient()

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2024년 11월 25일
In R2022b, R2023a, and R2023b, https://www.mathworks.com/help/releases/R2023b/audio/ref/speech2text.html has a different calling sequence.
The calling sequence changed as of R2024a.

Sandeep Mishra
Sandeep Mishra 2024년 11월 25일
Hi Anurag,
I also encountered a similar error while running the code snippet in MATLAB R2023b.
The problem arises due to the version mismatch between MATLAB on the local machine (R2023b) and the MATLAB Online (R2024b).
From the release notes, it can be observed that the 'speech2text' function requires a 'clientObj' parameter as the first argument up to MATLAB R2023b.
To resolve the issue and ensure compatibility with MATLAB R2023b, you can modify the code snippet to include a clientObj parameter as follows:
transcriber = speechClient("wav2vec2.0");
transcript = speech2text(transcriber, y,fs)
transcript = transcript.Transcript;
Refer to the following MathWorks Documentation to learn more about ‘speech2textfunction: https://www.mathworks.com/help/releases/R2023b/audio/ref/speech2text.html

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by