| 1 | #cxx . . $ `<file>/fon/SpeechRecognizer.h`/ifndef _SpeechRecognizer_h_ |
| 2 | #define _SpeechRecognizer_h_cxx . . $ `fon/SpeechRecognizer.h:2:9`! |
| 3 | /* SpeechRecognizer.h |
| 4 | * |
| 5 | * Copyright (C) 2025,2026 Anastasia Shchupak |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | * See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "Sound.h"cxx . . $ `<file>/fon/Sound.h`/ |
| 22 | #include <set> |
| 23 | |
| 24 | struct structSpeechRecognizercxx . . $ structSpeechRecognizer#; |
| 25 | struct whisper_contextcxx . . $ whisper_context#; |
| 26 | struct whisper_vad_contextcxx . . $ whisper_vad_context#; |
| 27 | struct whisper_vad_segmentscxx . . $ whisper_vad_segments#; |
| 28 | struct diarize_contextcxx . . $ diarize_context#; |
| 29 | |
| 30 | struct autoWhisperContextcxx . . $ autoWhisperContext# { |
| 31 | whisper_contextcxx . . $ whisper_context# *ptrcxx . . $ autoWhisperContext#ptr.; |
| 32 | |
| 33 | autoWhisperContextcxx . . $ autoWhisperContext#autoWhisperContext(50fba0c8e4acf21c). (whisper_contextcxx . . $ whisper_context# *p = nullptr) : ptrcxx . . $ autoWhisperContext#ptr.(p) {} |
| 34 | ~cxx . . $ autoWhisperContext#`~autoWhisperContext`(ced63f7c635d850d).autoWhisperContextcxx . . $ autoWhisperContext# (); |
| 35 | |
| 36 | autoWhisperContextcxx . . $ autoWhisperContext#autoWhisperContext(9164b3e16887e7af). (const autoWhisperContextcxx . . $ autoWhisperContext#&) = delete; |
| 37 | autoWhisperContextcxx . . $ autoWhisperContext#& operatorcxx . . $ autoWhisperContext#`operator=`(1808ea18fffc245).= (const autoWhisperContextcxx . . $ autoWhisperContext#&) = delete; |
| 38 | |
| 39 | autoWhisperContextcxx . . $ autoWhisperContext#autoWhisperContext(ac7b3622f9a3bb03). (autoWhisperContextcxx . . $ autoWhisperContext#&& other) noexcept : ptrcxx . . $ autoWhisperContext#ptr. (other.ptrcxx . . $ autoWhisperContext#ptr.) { |
| 40 | other.ptrcxx . . $ autoWhisperContext#ptr. = nullptr; |
| 41 | } |
| 42 | autoWhisperContextcxx . . $ autoWhisperContext#& operatorcxx . . $ autoWhisperContext#`operator=`(dceedb20f2fe0c93).= (autoWhisperContextcxx . . $ autoWhisperContext#&& other) noexcept; |
| 43 | |
| 44 | [[nodiscard]] |
| 45 | whisper_contextcxx . . $ whisper_context# *getcxx . . $ autoWhisperContext#get(9bd6dc1778dd7f42). () const { return ptrcxx . . $ autoWhisperContext#ptr.; } |
| 46 | }; |
| 47 | |
| 48 | struct autoWhisperVadContextcxx . . $ autoWhisperVadContext# { |
| 49 | whisper_vad_contextcxx . . $ whisper_vad_context# *ptrcxx . . $ autoWhisperVadContext#ptr.; |
| 50 | |
| 51 | autoWhisperVadContextcxx . . $ autoWhisperVadContext#autoWhisperVadContext(da59a243252bfe1d). (whisper_vad_contextcxx . . $ whisper_vad_context# *p = nullptr) : ptrcxx . . $ autoWhisperVadContext#ptr. (p) {} |
| 52 | ~cxx . . $ autoWhisperVadContext#`~autoWhisperVadContext`(49f6e7a06ebc5aa8).autoWhisperVadContextcxx . . $ autoWhisperVadContext# (); |
| 53 | |
| 54 | autoWhisperVadContextcxx . . $ autoWhisperVadContext#autoWhisperVadContext(fcaedff12a8c6c3f). (const autoWhisperVadContextcxx . . $ autoWhisperVadContext#&) = delete; |
| 55 | autoWhisperVadContextcxx . . $ autoWhisperVadContext#& operatorcxx . . $ autoWhisperVadContext#`operator=`(1f36c944e27757fc).= (const autoWhisperVadContextcxx . . $ autoWhisperVadContext#&) = delete; |
| 56 | |
| 57 | autoWhisperVadContextcxx . . $ autoWhisperVadContext#autoWhisperVadContext(bcc12b602f4728f4). (autoWhisperVadContextcxx . . $ autoWhisperVadContext#&& other) noexcept : ptrcxx . . $ autoWhisperVadContext#ptr. (other.ptrcxx . . $ autoWhisperVadContext#ptr.) { |
| 58 | other.ptrcxx . . $ autoWhisperVadContext#ptr. = nullptr; |
| 59 | } |
| 60 | autoWhisperVadContextcxx . . $ autoWhisperVadContext#& operatorcxx . . $ autoWhisperVadContext#`operator=`(29556fddf54d2da3).= (autoWhisperVadContextcxx . . $ autoWhisperVadContext#&& other) noexcept; |
| 61 | |
| 62 | [[nodiscard]] |
| 63 | whisper_vad_contextcxx . . $ whisper_vad_context# *getcxx . . $ autoWhisperVadContext#get(f343f8db3fc0e891). () const { return ptrcxx . . $ autoWhisperVadContext#ptr.; } |
| 64 | }; |
| 65 | |
| 66 | struct autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments# { |
| 67 | whisper_vad_segmentscxx . . $ whisper_vad_segments# *ptrcxx . . $ autoWhisperVadSegments#ptr.; |
| 68 | |
| 69 | autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments#autoWhisperVadSegments(89f830c8e2da71db). (whisper_vad_segmentscxx . . $ whisper_vad_segments# *p = nullptr) : ptrcxx . . $ autoWhisperVadSegments#ptr. (p) {} |
| 70 | ~cxx . . $ autoWhisperVadSegments#`~autoWhisperVadSegments`(49f6e7a06ebc5aa8).autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments# (); |
| 71 | |
| 72 | autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments#autoWhisperVadSegments(457b2c80a359b9bf). (const autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments#&) = delete; |
| 73 | autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments#& operatorcxx . . $ autoWhisperVadSegments#`operator=`(c0886be70a0a241).= (const autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments#&) = delete; |
| 74 | |
| 75 | autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments#autoWhisperVadSegments(e3765633c776abfe). (autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments# && other) noexcept : ptrcxx . . $ autoWhisperVadSegments#ptr. (other.ptrcxx . . $ autoWhisperVadSegments#ptr.) { |
| 76 | other.ptrcxx . . $ autoWhisperVadSegments#ptr. = nullptr; |
| 77 | } |
| 78 | autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments#& operatorcxx . . $ autoWhisperVadSegments#`operator=`(1ee7ca4d4e20f33b).= (autoWhisperVadSegmentscxx . . $ autoWhisperVadSegments# && other) noexcept; |
| 79 | |
| 80 | [[nodiscard]] |
| 81 | whisper_vad_segmentscxx . . $ whisper_vad_segments# *getcxx . . $ autoWhisperVadSegments#get(7531d5737aaa08aa). () const { return ptrcxx . . $ autoWhisperVadSegments#ptr.; } |
| 82 | }; |
| 83 | |
| 84 | struct autoDiarizeContextcxx . . $ autoDiarizeContext# { |
| 85 | diarize_contextcxx . . $ diarize_context# *ptrcxx . . $ autoDiarizeContext#ptr.; |
| 86 | |
| 87 | autoDiarizeContextcxx . . $ autoDiarizeContext#autoDiarizeContext(6dc7b3cba0cf7d7a). (diarize_contextcxx . . $ diarize_context# *p = nullptr) : ptrcxx . . $ autoDiarizeContext#ptr.(p) {} |
| 88 | ~cxx . . $ autoDiarizeContext#`~autoDiarizeContext`(49f6e7a06ebc5aa8).autoDiarizeContextcxx . . $ autoDiarizeContext# (); |
| 89 | |
| 90 | autoDiarizeContextcxx . . $ autoDiarizeContext#autoDiarizeContext(e7b96c5f114077bb). (const autoDiarizeContextcxx . . $ autoDiarizeContext#&) = delete; |
| 91 | autoDiarizeContextcxx . . $ autoDiarizeContext#& operatorcxx . . $ autoDiarizeContext#`operator=`(fcc71b37ed866f26).= (const autoDiarizeContextcxx . . $ autoDiarizeContext#&) = delete; |
| 92 | |
| 93 | autoDiarizeContextcxx . . $ autoDiarizeContext#autoDiarizeContext(dfde884341aa0b9e). (autoDiarizeContextcxx . . $ autoDiarizeContext#&& other) noexcept : ptrcxx . . $ autoDiarizeContext#ptr.(other.ptrcxx . . $ autoDiarizeContext#ptr.) { |
| 94 | other.ptrcxx . . $ autoDiarizeContext#ptr. = nullptr; |
| 95 | } |
| 96 | autoDiarizeContextcxx . . $ autoDiarizeContext#& operatorcxx . . $ autoDiarizeContext#`operator=`(ed12d908610be2c8).= (autoDiarizeContextcxx . . $ autoDiarizeContext#&& other) noexcept; |
| 97 | |
| 98 | [[nodiscard]] |
| 99 | diarize_contextcxx . . $ diarize_context# *getcxx . . $ autoDiarizeContext#get(77350513ca2629e6). () const { return ptrcxx . . $ autoDiarizeContext#ptr.; } |
| 100 | }; |
| 101 | |
| 102 | /* |
| 103 | Default parameter values for the UI. |
| 104 | */ |
| 105 | namespace TranscriptionDefaultscxx . . $ TranscriptionDefaults/ { |
| 106 | inline constexpr conststring32cxx . . $ conststring32# modelNamecxx . . $ TranscriptionDefaults/modelName. = U"ggml-base.bin"; |
| 107 | inline constexpr conststring32cxx . . $ conststring32# languageNamecxx . . $ TranscriptionDefaults/languageName. = U"Autodetect language"; |
| 108 | inline constexpr bool includeWordscxx . . $ TranscriptionDefaults/includeWords. = true; |
| 109 | inline constexpr bool includeDiarizationcxx . . $ TranscriptionDefaults/includeDiarization. = false; |
| 110 | inline constexpr bool useVadcxx . . $ TranscriptionDefaults/useVad. = true; |
| 111 | inline const integercxx . . $ integer# n_threadscxx . . $ TranscriptionDefaults/n_threads. = MelderThread_getNumberOfProcessorscxx . . $ MelderThread_getNumberOfProcessors(da6335ded91d79c2). () / 2; |
| 112 | } |
| 113 | |
| 114 | namespace VadDefaultscxx . . $ VadDefaults/ { |
| 115 | inline constexpr conststring32cxx . . $ conststring32# speechThresholdcxx . . $ VadDefaults/speechThreshold. = U"0.5"; |
| 116 | inline constexpr conststring32cxx . . $ conststring32# minNonSpeechDurationcxx . . $ VadDefaults/minNonSpeechDuration. = U"0.1"; |
| 117 | inline constexpr conststring32cxx . . $ conststring32# minSpeechDurationcxx . . $ VadDefaults/minSpeechDuration. = U"0.25"; |
| 118 | inline constexpr conststring32cxx . . $ conststring32# speechPadcxx . . $ VadDefaults/speechPad. = U"0.0"; |
| 119 | inline constexpr conststring32cxx . . $ conststring32# nonSpeechLabelcxx . . $ VadDefaults/nonSpeechLabel. = U""; |
| 120 | inline constexpr conststring32cxx . . $ conststring32# speechLabelcxx . . $ VadDefaults/speechLabel. = U"speech"; |
| 121 | } |
| 122 | |
| 123 | namespace DiarizationDefaultscxx . . $ DiarizationDefaults/ { |
| 124 | inline constexpr conststring32cxx . . $ conststring32# maxNumSpeakerscxx . . $ DiarizationDefaults/maxNumSpeakers. = U"2"; |
| 125 | inline constexpr bool allowOverlapcxx . . $ DiarizationDefaults/allowOverlap. = true; |
| 126 | inline constexpr conststring32cxx . . $ conststring32# nonSpeechLabelcxx . . $ DiarizationDefaults/nonSpeechLabel. = U""; |
| 127 | inline constexpr conststring32cxx . . $ conststring32# speechLabelcxx . . $ DiarizationDefaults/speechLabel. = U"speech"; |
| 128 | inline constexpr conststring32cxx . . $ conststring32# clusterThresholdcxx . . $ DiarizationDefaults/clusterThreshold. = U"0.7"; |
| 129 | inline constexpr conststring32cxx . . $ conststring32# segmentationStepcxx . . $ DiarizationDefaults/segmentationStep. = U"0.1"; |
| 130 | inline const integercxx . . $ integer# n_threadscxx . . $ DiarizationDefaults/n_threads. = MelderThread_getNumberOfProcessorscxx . . $ MelderThread_getNumberOfProcessors(da6335ded91d79c2). () / 2; |
| 131 | } |
| 132 | |
| 133 | struct SpeechSegmentcxx . . $ SpeechSegment# { |
| 134 | autostring32cxx . . $ autostring32# textcxx . . $ SpeechSegment#text.; |
| 135 | double tmincxx . . $ SpeechSegment#tmin.; |
| 136 | double tmaxcxx . . $ SpeechSegment#tmax.; |
| 137 | }; |
| 138 | |
| 139 | struct WhisperTranscriptioncxx . . $ WhisperTranscription# { |
| 140 | SpeechSegmentcxx . . $ SpeechSegment# fullTranscriptioncxx . . $ WhisperTranscription#fullTranscription.; |
| 141 | autovectorcxx . . $ autovector# <SpeechSegmentcxx . . $ SpeechSegment#> wordscxx . . $ WhisperTranscription#words.; |
| 142 | autovectorcxx . . $ autovector# <SpeechSegmentcxx . . $ SpeechSegment#> sentencescxx . . $ WhisperTranscription#sentences.; |
| 143 | }; |
| 144 | |
| 145 | inline stdcxx . . $ std/::setcxx . . $ std/set# <structSpeechRecognizercxx . . $ structSpeechRecognizer# *> theLivingSpeechRecognizerscxx . . $ std/set#set(49f6e7a06ebc5aa8).; |
| 146 | #include "SpeechRecognizer_def.h"cxx . . $ `<file>/fon/SpeechRecognizer_def.h`/ |
| 147 | |
| 148 | /* |
| 149 | Functions to access lists of models and languages from everywhere. |
| 150 | */ |
| 151 | constSTRVECcxx . . $ constSTRVEC# theCurrentSpeechRecognizerModelNamescxx . . $ theCurrentSpeechRecognizerModelNames(6d96a063d275a0aa). (); |
| 152 | constSTRVECcxx . . $ constSTRVEC# theSpeechRecognizerLanguageNamescxx . . $ theSpeechRecognizerLanguageNames(6d96a063d275a0aa). (); |
| 153 | |
| 154 | /* |
| 155 | Class SpeechRecognizer functions. |
| 156 | */ |
| 157 | autoSpeechRecognizercxx . . $ autoSpeechRecognizer# SpeechRecognizer_createcxx . . $ SpeechRecognizer_create(159722423569d923). (conststring32cxx . . $ conststring32# modelName, conststring32cxx . . $ conststring32# languageName); |
| 158 | WhisperTranscriptioncxx . . $ WhisperTranscription# SpeechRecognizer_recognizecxx . . $ SpeechRecognizer_recognize(c5e825ed147f56af). (constSpeechRecognizercxx . . $ constSpeechRecognizer# me, constSoundcxx . . $ constSound# sound, bool useVad, |
| 159 | double speechProbabilityThreshold, double minNonSpeechDuration, double minSpeechDuration, double speechPad); |
| 160 | |
| 161 | /* |
| 162 | Silero-VAD functions. |
| 163 | */ |
| 164 | autovectorcxx . . $ autovector# <SpeechSegmentcxx . . $ SpeechSegment#> doSileroVadcxx . . $ doSileroVad(34a52605c8efc429). (constSoundcxx . . $ constSound# sound, double speechProbabilityThreshold, double minNonSpeechDuration, |
| 165 | double minSpeechDuration, double speechPad, conststring32cxx . . $ conststring32# nonSpeechLabel, conststring32cxx . . $ conststring32# speechLabel); |
| 166 | |
| 167 | /* |
| 168 | Diarization functions. |
| 169 | */ |
| 170 | /* |
| 171 | Run speaker diarization on Sound. Return a vector of timelines, one timeline per speaker. |
| 172 | Each timeline covers [sound->xmin, sound->xmax] as alternating silent/active intervals, |
| 173 | labeled `nonSpeechLabel` and `speechLabel` respectively. |
| 174 | */ |
| 175 | autovectorcxx . . $ autovector# <autovectorcxx . . $ autovector# <SpeechSegmentcxx . . $ SpeechSegment#>> doDiarizationcxx . . $ doDiarization(fb99a7b1dc80f916). (constSoundcxx . . $ constSound# sound, |
| 176 | integercxx . . $ integer# maxNumSpeakers, bool allowSpeakersOverlap, |
| 177 | double clusterThreshold, double segmentationStep, |
| 178 | conststring32cxx . . $ conststring32# nonSpeechLabel, conststring32cxx . . $ conststring32# speechLabel); |
| 179 | |
| 180 | /* |
| 181 | Preferences for AI settings (maximum number of threads for transcription & diarization). |
| 182 | */ |
| 183 | void SpeechRecognizer_preferencescxx . . $ SpeechRecognizer_preferences(49f6e7a06ebc5aa8). (); |
| 184 | |
| 185 | void SpeechRecognizer_setMaxNumberOfThreadsForTranscriptioncxx . . $ SpeechRecognizer_setMaxNumberOfThreadsForTranscription(1624ee8275b10bda). (integercxx . . $ integer# numberOfThreads); |
| 186 | void SpeechRecognizer_setMaxNumberOfThreadsForDiarizationcxx . . $ SpeechRecognizer_setMaxNumberOfThreadsForDiarization(1624ee8275b10bda). (integercxx . . $ integer# numberOfThreads); |
| 187 | |
| 188 | integercxx . . $ integer# SpeechRecognizer_getMaxNumberOfThreadsForTranscriptioncxx . . $ SpeechRecognizer_getMaxNumberOfThreadsForTranscription(da6335ded91d79c2). (); |
| 189 | integercxx . . $ integer# SpeechRecognizer_getMaxNumberOfThreadsForDiarizationcxx . . $ SpeechRecognizer_getMaxNumberOfThreadsForDiarization(da6335ded91d79c2). (); |
| 190 | |
| 191 | /* End of file SpeechRecognizer.h */ |
| 192 | #endif |