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

% 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 Comments

Could you please provide the error message you encounter when running the code on your local PC?
Incorrect number or types of inputs or outputs for function isvalid.
Error in speech2text
In R2023b the syntax is
transcript = speech2text(clientObj,audioIn,fs)
where clientObj is returned by speechClient()

Sign in to comment.

Answers (2)

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

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Products

Release

R2023b

Asked:

on 25 Nov 2024

Answered:

on 25 Nov 2024

Community Treasure Hunt

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

Start Hunting!