Clear Filters
Clear Filters

Free-to-use speech-to-text conversion using MATLAB interface to .NET

20 views (last 30 days)
I - like quite a few other other posters here - would like to perform realtime speech-to-text conversion within MATLAB.
One approach is to use the groovy new Deep Learning Speech Recognition example code but that would require appropriate trainging data (which is hard to acquire).
Another approach is the speech2text code posted by Gabriele Bunkheila:
allowing MATLAB to access various 3rd party speech-to-text web services. Unfortunately all of these are paid subscription services.
I would like to access the free-to-use and perfectly good speech-to-text services built into Windows and accessed via the MS Speech API.
Some time ago Michelle Hirsch posted a code fragment (it's copied below ) written by a Matlab staffer (Jiro) suggesting this was possible
function rec = speechrecognition
% Add assembly
% Construct engine
rec = System.Speech.Recognition.SpeechRecognitionEngine;
% Define listener callback
addlistener(rec, 'SpeechRecognized', @recognizedFcn);
% Start recognition
% Callback
function recognizedFcn(obj, e)
% Get text
txt = char(e.Result.Text);
% Split into words
w = regexp(txt, '\s', 'split');
if length(w) > 1
% Look for the occurrence of the phrase "search for"
idx = find(strcmp(w(1:end-1), 'search') & ...
strcmp(w(2:end), 'for'), 1, 'first');
if ~isempty(idx) && length(w) >= idx+2
% The words after are the search terms
searchTerm = sprintf('%s+', w{idx+2:end});
searchTerm(end) = '';
% Search on the web
web(['', searchTerm]);
fprintf(2, 'search for "%s"\n', strrep(searchTerm, '+', ' '));
elseif length(w) == 1 && strcmpi(w{1}, 'stop')
disp('Stopping Speech Recognition. Thank you for using!');
Has anyone got this to work? It may be a simple for for someone with experience of .NET programming in MATLAB to get this going...
I certainly think this would be useful to many people. Any pointers appreciated.
Steven Dakin

Answers (3)

Nikos Korobos
Nikos Korobos on 23 Mar 2022
Hello, did you get it to work?

Brian Hemmat
Brian Hemmat on 25 Mar 2022
Hi Steven,
You can try out wav2vec 2.0. You can find a MATLAB implementation here:
Brian Hemmat
Brian Hemmat on 28 Mar 2022
ascii encodes characters as numerics:
If I look at the table under printable characters, I see you wrote: HELLO
I think you want to use fprintf instead. Something like this pattern (adapt as needed, replace string with output of wav2vec etc):
fileID = fopen('foo.txt','w');

Sign in to comment.

Swathi on 13 Sep 2022
I understand that the intent was to perform real-time speech-to-text conversion within MATLAB.
It has been mentioned that the existing Deep Learning Recognition approach, the speech2text approach and some third party speech to text conversion websites require a paid subscription. Therefore, it is noted that using the conventional and freely available inbuilt Windows speech-to-text services by accessing it via the MS Speech API is preferable.
A reference to a code snippet and a workaround suggested by some of our staff members has also been observed.
In order to get that piece of code working, it is suggested to try out ‘wav2vec 2.0’, whose MATLAB implementation can be found here:
In addition, it is to be noted that,
  • The output of the wav2vec function can be written to a txt file to save it.
  • Thewav2vec’ always returns a string, which needs to be converted into a char to be written to an ASCII file as -
txt = char(txt);


Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!