Debian Codegraph @

fon/praat_SpeechRecognizer.cpp

raw symbols SCIP
1 /* praat_SpeechRecognizer.cpp
2 *
3 * Copyright (C) 2025 Anastasia Shchupak
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "praat_SpeechRecognizer.h"cxx . . $ `<file>/fon/praat_SpeechRecognizer.h`/
20 #include "SpeechRecognizer.h"cxx . . $ `<file>/fon/SpeechRecognizer.h`/
21 #include "praatM.h"cxx . . $ `<file>/sys/praatM.h`/
22
23
24 DIRECTcxx . . $ `sys/praatM.h:412:9`! (HELP__SpeechRecognizer_help) {
25 HELPcxx . . $ `sys/praatM.h:616:9`! (U"SpeechRecognizer")
26 }
27
28 FORMcxx . . $ `sys/praatM.h:79:9`! (CREATE_ONE__SpeechRecognizer_create, U"Create SpeechRecognizer", U"Create SpeechRecognizer...") {
29 LISTNUMSTRcxx . . $ `sys/praatM.h:307:9`! (modelIndex, modelName, U"Whisper model", constSTRVEC(), 1)
30 LISTNUMSTRcxx . . $ `sys/praatM.h:307:9`! (languageIndex, languageName, U"Language", constSTRVEC(), 1)
31 OKcxx . . $ `sys/praatM.h:327:9`!
32 static autoSTRVECcxx . . $ autoSTRVEC# modelNamescxx . . $ _autostringautovector#_autostringautovector(49f6e7a06ebc5aa8).;
33 modelNames =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). copy_STRVECcxx . . $ copy_STRVEC(cfa8029879abedac). (theCurrentSpeechRecognizerModelNamescxx . . $ theCurrentSpeechRecognizerModelNames(6d96a063d275a0aa).()); // cannot be called twice in the same scope
34
35 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (modelNames.size > 0,
36 U"Found no Whisper-cpp models to do speech recognition with.\n"
37 U"You can install them into the subfolder “whispercpp” of the folder “models” in the Praat preferences folder."
38 );
39
40 SET_LISTcxx . . $ `sys/praatM.h:351:9`! (modelIndex, modelName, modelNames.get(), NUMfindFirst (modelNames.get(), TranscriptionDefaults::modelName))
41 SET_LISTcxx . . $ `sys/praatM.h:351:9`! (languageIndex, languageName, theSpeechRecognizerLanguageNames(),
42 NUMfindFirst (theSpeechRecognizerLanguageNames(), TranscriptionDefaults::languageName))
43 DOcxx . . $ `sys/praatM.h:354:9`!
44 CREATE_ONEcxx . . $ `sys/praatM.h:485:9`!
45 autoSpeechRecognizercxx . . $ autoSpeechRecognizer# result = SpeechRecognizer_createcxx . . $ SpeechRecognizer_create(159722423569d923). (modelName, languageName);
46 Thing_setNamecxx . . $ Thing_setName(b5a42e5e01c267b5). (result.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (modelName, U"_", languageName));
47 CREATE_ONE_ENDcxx . . $ `sys/praatM.h:486:9`! (U"")
48 }
49
50 DIRECTcxx . . $ `sys/praatM.h:412:9`! (QUERY_ONE_FOR_STRING__SpeechRecognizer_getModelName) {
51 QUERY_ONE_FOR_STRINGcxx . . $ `sys/praatM.h:931:9`! (SpeechRecognizer)
52 conststring32cxx . . $ conststring32# result = mycxx . . $ `melder/melder.h:44:9`! d_modelNamecxx . . $ structSpeechRecognizer#d_modelName..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
53 QUERY_ONE_FOR_STRING_ENDcxx . . $ `sys/praatM.h:933:9`!
54 }
55
56 DIRECTcxx . . $ `sys/praatM.h:412:9`! (QUERY_ONE_FOR_STRING__SpeechRecognizer_getLanguageName) {
57 QUERY_ONE_FOR_STRINGcxx . . $ `sys/praatM.h:931:9`! (SpeechRecognizer)
58 conststring32cxx . . $ conststring32# result = mycxx . . $ `melder/melder.h:44:9`! d_languageNamecxx . . $ structSpeechRecognizer#d_languageName..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
59 QUERY_ONE_FOR_STRING_ENDcxx . . $ `sys/praatM.h:933:9`!
60 }
61
62 DIRECTcxx . . $ `sys/praatM.h:412:9`! (QUERY_ONE_AND_ONE_FOR_STRING__SpeechRecognizer_Sound_recognize) {
63 QUERY_ONE_AND_ONE_FOR_STRINGcxx . . $ `sys/praatM.h:977:9`! (SpeechRecognizer, Sound)
64 bool useVad = true;
65 /*
66 Use default Silero VAD parameters.
67 FIXME make them configurable, like in other places
68 */
69 double speechProbabilityThreshold = 0.5; // probability threshold to decide that sound is speech
70 double minNonSpeechDuration = 0.1; // min duration of a non-speech segment
71 double minSpeechDuration = 0.25; // min duration of a speech segment
72 double speechPad = 0.03; // padding added before and after each speech segment
73 WhisperTranscriptioncxx . . $ WhisperTranscription# whisperTranscription = SpeechRecognizer_recognizecxx . . $ SpeechRecognizer_recognize(c5e825ed147f56af). (me, you, useVad,
74 speechProbabilityThreshold, minNonSpeechDuration, minSpeechDuration, speechPad);
75 conststring32cxx . . $ conststring32# result = whisperTranscription.fullTranscriptioncxx . . $ WhisperTranscription#fullTranscription..textcxx . . $ SpeechSegment#text..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
76 QUERY_ONE_AND_ONE_FOR_STRING_ENDcxx . . $ `sys/praatM.h:979:9`!
77 }
78
79 FORMcxx . . $ `sys/praatM.h:79:9`! (SETTINGS__SpeechRecognizerSettings, U"AI settings", nullptr) {
80 COMMENTcxx . . $ `sys/praatM.h:136:9`! (U"These settings determine how fast transcription and diarization")
81 COMMENTcxx . . $ `sys/praatM.h:136:9`! (U"procedures are performed on your computer.")
82 HEADINGcxx . . $ `sys/praatM.h:134:9`! (U"Transcription...")
83 INTEGERcxx . . $ `sys/praatM.h:108:9`! (maxNumberOfThreadsForTranscription, U"Max. number of threads", U"0 (= auto)")
84 CAPTIONcxx . . $ `sys/praatM.h:138:9`! (Melder_cat (U"(“auto” is ", TranscriptionDefaults::n_threads, U" on this computer)"))
85 HEADINGcxx . . $ `sys/praatM.h:134:9`! (U"Diarization...")
86 INTEGERcxx . . $ `sys/praatM.h:108:9`! (maxNumberOfThreadsForDiarization, U"Max. number of threads", U"0 (= auto)")
87 CAPTIONcxx . . $ `sys/praatM.h:138:9`! (Melder_cat (U"(“auto” is ", DiarizationDefaults::n_threads, U" on this computer)"))
88 OKcxx . . $ `sys/praatM.h:327:9`!
89 SET_INTEGERcxx . . $ `sys/praatM.h:335:9`! (maxNumberOfThreadsForTranscription, SpeechRecognizer_getMaxNumberOfThreadsForTranscription ())
90 SET_INTEGERcxx . . $ `sys/praatM.h:335:9`! (maxNumberOfThreadsForDiarization, SpeechRecognizer_getMaxNumberOfThreadsForDiarization ())
91 DOcxx . . $ `sys/praatM.h:354:9`!
92 PREFScxx . . $ `sys/praatM.h:1377:9`!
93 SpeechRecognizer_setMaxNumberOfThreadsForTranscriptioncxx . . $ SpeechRecognizer_setMaxNumberOfThreadsForTranscription(1624ee8275b10bda). (maxNumberOfThreadsForTranscription);
94 SpeechRecognizer_setMaxNumberOfThreadsForDiarizationcxx . . $ SpeechRecognizer_setMaxNumberOfThreadsForDiarization(1624ee8275b10bda). (maxNumberOfThreadsForDiarization);
95 PREFS_ENDcxx . . $ `sys/praatM.h:1378:9`!
96 }
97
98 void praat_SpeechRecognizer_initcxx . . $ praat_SpeechRecognizer_init(49f6e7a06ebc5aa8). () {
99 Thing_recognizeClassesByNamecxx . . $ Thing_recognizeClassesByName(b2b8400651464df9). (classSpeechRecognizercxx . . $ classSpeechRecognizer.);
100
101 SpeechRecognizer_preferencescxx . . $ SpeechRecognizer_preferences(49f6e7a06ebc5aa8). ();
102
103 praat_addMenuCommandcxx . . $ `sys/praat.h:116:9`! (U"Objects", U"New", U"Speech-to-text recognition", nullptr, 0, nullptr);
104 praat_addMenuCommandcxx . . $ `sys/praat.h:116:9`! (U"Objects", U"New", U"SpeechRecognizer help", nullptr, 1, HELP__SpeechRecognizer_help);
105 praat_addMenuCommandcxx . . $ `sys/praat.h:116:9`! (U"Objects", U"New", U"-- new SpeechRecognizer --", nullptr, 1, nullptr);
106 praat_addMenuCommandcxx . . $ `sys/praat.h:116:9`! (U"Objects", U"New", U"Create SpeechRecognizer...", nullptr, 1, CREATE_ONE__SpeechRecognizer_create);
107 praat_addMenuCommandcxx . . $ `sys/praat.h:116:9`! (U"Objects", U"Settings", U"-- AI settings --", nullptr, 0, nullptr);
108 praat_addMenuCommandcxx . . $ `sys/praat.h:116:9`! (U"Objects", U"Settings", U"AI settings...", nullptr, 0, SETTINGS__SpeechRecognizerSettings);
109
110 praat_addAction1cxx . . $ `sys/praat.h:72:9`! (classSpeechRecognizer, 0, U"SpeechRecognizer help", nullptr, 0,
111 HELP__SpeechRecognizer_help);
112 praat_addAction1cxx . . $ `sys/praat.h:72:9`! (classSpeechRecognizer, 0, U"Query -", nullptr, 0, nullptr);
113 praat_addAction1cxx . . $ `sys/praat.h:72:9`! (classSpeechRecognizer, 1, U"Get Whisper model name", nullptr, 1,
114 QUERY_ONE_FOR_STRING__SpeechRecognizer_getModelName);
115 praat_addAction1cxx . . $ `sys/praat.h:72:9`! (classSpeechRecognizer, 1, U"Get language name", nullptr, 1,
116 QUERY_ONE_FOR_STRING__SpeechRecognizer_getLanguageName);
117
118 praat_addAction2cxx . . $ `sys/praat.h:73:9`! (classSpeechRecognizer, 1, classSound, 1, U"Transcribe", nullptr, 0,
119 QUERY_ONE_AND_ONE_FOR_STRING__SpeechRecognizer_Sound_recognize);
120 }