File indexing completed on 2024-12-22 04:28:23
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "voskspeechtotextplugin.h" 0008 #include "speechtotext_vosk_debug.h" 0009 #include "voskspeechtotextdevice.h" 0010 #include <QIODevice> 0011 0012 VoskSpeechToTextPlugin::VoskSpeechToTextPlugin(QObject *parent) 0013 : TextSpeechToText::SpeechToTextPlugin{parent} 0014 , mDevice(new VoskSpeechToTextDevice(this)) 0015 { 0016 connect(mDevice, &VoskSpeechToTextDevice::result, this, &VoskSpeechToTextPlugin::speechToTextDone); 0017 } 0018 0019 VoskSpeechToTextPlugin::~VoskSpeechToTextPlugin() = default; 0020 0021 void VoskSpeechToTextPlugin::speechToText() 0022 { 0023 if (!mDevice->available()) { 0024 qCWarning(SPEECHTOTEXT_VOSK_LOG) << "Vosk is not available"; 0025 return; 0026 } 0027 // TODO 0028 } 0029 0030 int VoskSpeechToTextPlugin::sampleRate() const 0031 { 0032 return 16000; 0033 } 0034 0035 QIODevice *VoskSpeechToTextPlugin::audioDevice() const 0036 { 0037 return mDevice; 0038 } 0039 0040 bool VoskSpeechToTextPlugin::loadSettings() 0041 { 0042 // First setSampleRate 0043 VoskSpeechToTextDevice::VoskSpeechToTextDeviceInfo info; 0044 info.sampleRate = sampleRate(); 0045 if (!mDevice->initialize(std::move(info))) { 0046 qCWarning(SPEECHTOTEXT_VOSK_LOG) << "Impossible to initialize vosk plugin"; 0047 return false; 0048 } 0049 return true; 0050 } 0051 0052 void VoskSpeechToTextPlugin::clear() 0053 { 0054 mDevice->clear(); 0055 } 0056 0057 #include "moc_voskspeechtotextplugin.cpp"