フィルターのクリア

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

30 ビュー (過去 30 日間)
Steven Dakin
Steven Dakin 2021 年 1 月 10 日
回答済み: Swathi 2022 年 9 月 13 日
Hi
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: https://www.mathworks.com/matlabcentral/fileexchange/65266-speech2text
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
NET.addAssembly('System.Speech');
% Construct engine
rec = System.Speech.Recognition.SpeechRecognitionEngine;
rec.SetInputToDefaultAudioDevice;
rec.LoadGrammar(System.Speech.Recognition.DictationGrammar);
% Define listener callback
addlistener(rec, 'SpeechRecognized', @recognizedFcn);
% Start recognition
rec.RecognizeAsync(System.Speech.Recognition.RecognizeMode.Multiple);
% 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(['http://www.google.com/search?q=', searchTerm]);
fprintf(2, 'search for "%s"\n', strrep(searchTerm, '+', ' '));
else
%disp(txt)
end
elseif length(w) == 1 && strcmpi(w{1}, 'stop')
obj.RecognizeAsyncStop;
obj.delete;
%disp(txt);
disp('Stopping Speech Recognition. Thank you for using!');
else
%disp(txt);
end
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.
Cheers
Steven Dakin

回答 (3 件)

Nikos Korobos
Nikos Korobos 2022 年 3 月 23 日
Hello, did you get it to work?

Brian Hemmat
Brian Hemmat 2022 年 3 月 25 日
Hi Steven,
You can try out wav2vec 2.0. You can find a MATLAB implementation here:
  5 件のコメント
Brian Hemmat
Brian Hemmat 2022 年 3 月 28 日
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');
fprintf(fileID,"abc"+newline);
fprintf(fileID,"def"+newline);
fclose(fileID);
Nikos Korobos
Nikos Korobos 2022 年 3 月 28 日
Thanks again managed to get it working with
writematrix(txt,'sttfile.txt' );

サインインしてコメントする。


Swathi
Swathi 2022 年 9 月 13 日
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);
or
writematrix(txt,'<filename>');

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by