From 1fa840757f37c76af5a9bbe1e0e074e9f3e590ee Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 13 Mar 2021 19:34:42 +0200 Subject: [PATCH] khotkeys: remove barely implemented voice trigger feature Signed-off-by: Ivailo Monev --- khotkeys/app/kded.cpp | 2 - khotkeys/libkhotkeysprivate/CMakeLists.txt | 6 - .../libkhotkeysprivate/khotkeysglobal.cpp | 6 - khotkeys/libkhotkeysprivate/settings.cpp | 19 - khotkeys/libkhotkeysprivate/settings.h | 14 - .../libkhotkeysprivate/settings_writer.cpp | 2 - khotkeys/libkhotkeysprivate/sound.cpp | 343 -------------- khotkeys/libkhotkeysprivate/sound.h | 58 --- khotkeys/libkhotkeysprivate/soundrecorder.cpp | 81 ---- khotkeys/libkhotkeysprivate/soundrecorder.h | 62 --- .../libkhotkeysprivate/triggers/triggers.h | 45 -- .../triggers/voice_trigger.cpp | 86 ---- khotkeys/libkhotkeysprivate/voices.cpp | 287 ------------ khotkeys/libkhotkeysprivate/voices.h | 83 ---- .../libkhotkeysprivate/voicesignature.cpp | 423 ------------------ khotkeys/libkhotkeysprivate/voicesignature.h | 101 ----- 16 files changed, 1618 deletions(-) delete mode 100644 khotkeys/libkhotkeysprivate/sound.cpp delete mode 100644 khotkeys/libkhotkeysprivate/sound.h delete mode 100644 khotkeys/libkhotkeysprivate/soundrecorder.cpp delete mode 100644 khotkeys/libkhotkeysprivate/soundrecorder.h delete mode 100644 khotkeys/libkhotkeysprivate/triggers/voice_trigger.cpp delete mode 100644 khotkeys/libkhotkeysprivate/voices.cpp delete mode 100644 khotkeys/libkhotkeysprivate/voices.h delete mode 100644 khotkeys/libkhotkeysprivate/voicesignature.cpp delete mode 100644 khotkeys/libkhotkeysprivate/voicesignature.h diff --git a/khotkeys/app/kded.cpp b/khotkeys/app/kded.cpp index b19f3580..ad3a60b6 100644 --- a/khotkeys/app/kded.cpp +++ b/khotkeys/app/kded.cpp @@ -103,8 +103,6 @@ void KHotKeysModule::reread_configuration() kDebug() << _settings.areGesturesDisabled(); KHotKeys::gesture_handler->enable( !_settings.areGesturesDisabled() ); KHotKeys::gesture_handler->set_exclude( _settings.gesturesExclude() ); - // FIXME: SOUND - // KHotKeys::voice_handler->set_shortcut( _settings.voice_shortcut ); actions_root = _settings.actions(); KHotKeys::khotkeys_set_active( true ); } diff --git a/khotkeys/libkhotkeysprivate/CMakeLists.txt b/khotkeys/libkhotkeysprivate/CMakeLists.txt index fdba7b2a..a35b0d96 100644 --- a/khotkeys/libkhotkeysprivate/CMakeLists.txt +++ b/khotkeys/libkhotkeysprivate/CMakeLists.txt @@ -43,7 +43,6 @@ set(khotkeysprivate_SRCS triggers/trigger.cpp triggers/trigger_list.cpp triggers/triggers.cpp - # triggers/voice_trigger.cpp triggers/window_trigger.cpp # WINDOWS_HELPER @@ -62,11 +61,6 @@ set(khotkeysprivate_SRCS settings_writer.cpp shortcuts_handler.cpp windows_handler.cpp - # search for FIXME: SOUND - # sound.cpp - # soundrecorder.cpp - # voices.cpp - # voicesignature.cpp ) add_library(khotkeysprivate SHARED ${khotkeysprivate_SRCS}) diff --git a/khotkeys/libkhotkeysprivate/khotkeysglobal.cpp b/khotkeys/libkhotkeysprivate/khotkeysglobal.cpp index 75c32c23..0e4933ce 100644 --- a/khotkeys/libkhotkeysprivate/khotkeysglobal.cpp +++ b/khotkeys/libkhotkeysprivate/khotkeysglobal.cpp @@ -19,12 +19,8 @@ #include "windows_handler.h" #include "triggers/triggers.h" #include "triggers/gestures.h" -#include "voices.h" #include "shortcuts_handler.h" -// FIXME: SOUND -// #include "soundrecorder.h" - namespace KHotKeys { @@ -49,8 +45,6 @@ void init_global_data( bool active_P, QObject* owner_P ) { gesture_handler = new Gesture( active_P, owner_P ); } -// FIXME: SOUND -// static_cast< void >( new Voice( active_P, owner_P )); khotkeys_set_active( false ); } diff --git a/khotkeys/libkhotkeysprivate/settings.cpp b/khotkeys/libkhotkeysprivate/settings.cpp index b777be4e..8f9fb97f 100644 --- a/khotkeys/libkhotkeysprivate/settings.cpp +++ b/khotkeys/libkhotkeysprivate/settings.cpp @@ -169,9 +169,6 @@ void Settings::reinitialize() daemon_disabled = false; - // Currently unused - voice_shortcut = KShortcut(); - already_imported = QStringList(); } @@ -211,12 +208,6 @@ void Settings::setGestureTimeOut(int timeout) } -void Settings::setVoiceShortcut( const KShortcut &shortcut ) - { - voice_shortcut = shortcut; - } - - ActionDataGroup *Settings::takeActions() { ActionDataGroup *res = m_actions; @@ -225,12 +216,6 @@ ActionDataGroup *Settings::takeActions() } -KShortcut Settings::voiceShortcut() const - { - return voice_shortcut; - } - - bool Settings::import(KConfig& config, ImportType ask, ActionState state) { return importFrom(m_actions, config, ask, state); @@ -459,10 +444,6 @@ bool Settings::reread_settings(bool include_disabled) delete gestures_exclude; gestures_exclude = new Windowdef_list( gesturesExcludeConfig ); - // ### Voice - KConfigGroup voiceConfig( &config, "Voice" ); - voice_shortcut=KShortcut( voiceConfig.readEntry("Shortcut" , "") ); - bool rc = read_settings(m_actions, config, include_disabled, Retain); // Ensure the system groups exist validate(); diff --git a/khotkeys/libkhotkeysprivate/settings.h b/khotkeys/libkhotkeysprivate/settings.h index db732ae3..84321490 100644 --- a/khotkeys/libkhotkeysprivate/settings.h +++ b/khotkeys/libkhotkeysprivate/settings.h @@ -166,15 +166,6 @@ public: void setGesturesExclude( Windowdef_list *gestures ); Windowdef_list *gesturesExclude(); const Windowdef_list *gesturesExclude() const; - //@} - - /** - * @name Voice Commands - */ - //@{ - void setVoiceShortcut( const KShortcut &shortcut ); - KShortcut voiceShortcut() const; - //@} /** * Check if the given config file is a valid khotkeys file @@ -242,11 +233,6 @@ private: */ bool daemon_disabled; - /** - * The shortcut that triggers a voice command - */ - KShortcut voice_shortcut; - /** * List of id's for all imported files. */ diff --git a/khotkeys/libkhotkeysprivate/settings_writer.cpp b/khotkeys/libkhotkeysprivate/settings_writer.cpp index 3cf59457..086cef69 100644 --- a/khotkeys/libkhotkeysprivate/settings_writer.cpp +++ b/khotkeys/libkhotkeysprivate/settings_writer.cpp @@ -267,8 +267,6 @@ void SettingsWriter::writeTo(KConfigBase &config) } else config.deleteGroup( "GesturesExclude" ); - KConfigGroup voiceConfig( &config, "Voice" ); - voiceConfig.writeEntry("Shortcut" , _settings->voice_shortcut.toString() ); } diff --git a/khotkeys/libkhotkeysprivate/sound.cpp b/khotkeys/libkhotkeysprivate/sound.cpp deleted file mode 100644 index 70d05eac..00000000 --- a/khotkeys/libkhotkeysprivate/sound.cpp +++ /dev/null @@ -1,343 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Olivier Goffart * - * ogoffart@kde.org * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include "sound.h" -#include -#include -#include - - - - -Sound::Sound() -{ -} - - -Sound::~Sound() -{ -} - - -#define READ_FROM_STREAM(FORMAT,NAME) FORMAT NAME; stream >> NAME; -#define MAGIC(CH) { \ - stream >> magic; \ - if( magic != ( (CH)[0] | (CH)[1]<<8 | (CH)[2]<< 16 | (CH)[3] << 24 ) ) \ - { \ - kWarning() << "bad format " << magic << " != " << CH "\n";\ - return;\ - } } - -#define ABS(X) ( (X>0) ? X : -X ) - -void Sound::load(const QString& filename) -{ - kDebug() << filename; - data=QVector(); - QFile file(filename); - if(!file.open(IO_ReadOnly)) - { - kWarning() <<"unable to open file" ; - return; - } - QDataStream stream(&file); - stream.setByteOrder( QDataStream::LittleEndian ); - Q_INT32 magic; - - MAGIC("RIFF"); - READ_FROM_STREAM(quint32,ChunkSize); - MAGIC("WAVE"); - MAGIC("fmt "); - READ_FROM_STREAM(quint32,ChunkSize2); - READ_FROM_STREAM(Q_INT16,AudioFormat); - READ_FROM_STREAM(Q_UINT16,NumberOfChannels); - READ_FROM_STREAM(quint32,SampleRate); - _fs=SampleRate; - READ_FROM_STREAM(quint32,ByteRate); - READ_FROM_STREAM(Q_UINT16,BlockAlign); - READ_FROM_STREAM(Q_UINT16,BitsPerSample); - MAGIC("data"); - READ_FROM_STREAM(QByteArray,SoundData); - NumberOfChannels=1; //Wav i play are broken - - file.close(); - - uint BytePS=BitsPerSample/8; - uint NumberOfSamples = (SoundData.size())/(NumberOfChannels*BytePS); - - - data.resize(NumberOfSamples); - -// kDebug() << NumberOfSamples << " samples"; - - max=0; - for(unsigned long int f=0;fmax) - { - max=ABS(nb); - } - } - -/* static int q=0; - QString name="test" + QString::number(q++) + ".wav"; - save(name);*/ - -} - -#define SMAGIC(CH) { stream << ( Q_INT32) ( (CH)[0] | (CH)[1]<<8 | (CH)[2]<< 16 | (CH)[3] << 24 ) ; } - -void Sound::save(const QString& filename) const -{ - kDebug() << filename << " - " << data.size() << endl; - QFile file(filename); - if(!file.open(IO_WriteOnly)) - { - kWarning() <<"unable to open file" ; - return; - } - QDataStream stream(&file); - stream.setByteOrder( QDataStream::LittleEndian ); - - - QByteArray SoundData(data.size()*2, '\0'); - - for(long int f=0;f> 8; - -// kDebug() << data.at(f) << " / " << max << " = " << val << " | " << SoundData[ 2*f ] << " "<< SoundData[ 2*f+1 ] << endl; - } - - Q_UINT16 NumberOfChannels=2; - quint32 SampleRate=_fs; - - SMAGIC("RIFF"); - //READ_FROM_STREAM(quint32,ChunkSize); - stream << (quint32)(36+ SoundData.size()); - SMAGIC("WAVE"); - SMAGIC("fmt "); - //READ_FROM_STREAM(quint32,ChunkSize2); - stream << (quint32)(16); - //READ_FROM_STREAM(Q_INT16,AudioFormat); - stream << (Q_INT16)(1); - //READ_FROM_STREAM(Q_UINT16,NumberOfChannels); - stream << (Q_UINT16)(NumberOfChannels); - //READ_FROM_STREAM(quint32,SampleRate); - stream << (quint32)(SampleRate); - //READ_FROM_STREAM(quint32,ByteRate); - stream << (quint32)(NumberOfChannels*SampleRate*16/8); - //READ_FROM_STREAM(Q_UINT16,BlockAlign); - stream << (Q_UINT16)(16/8 *NumberOfChannels); - //READ_FROM_STREAM(Q_UINT16,BitsPerSample); - stream << (Q_UINT16)(16); - SMAGIC("data"); - //READ_FROM_STREAM(QByteArray,SoundData); - stream << SoundData; - - file.close(); - -} - - - - -#if 0 -void Sound::load(const QString& filename) -{ - cout << "saout \n"; - data=QMemArray(); - static const int BUFFER_LEN = 4096; - - //code from libtunepimp - //(wav_trm.cpp) - - FILE *source; - unsigned char buffer[100], *copyBuffer; - unsigned int bytes; - unsigned long ulRIFF; - unsigned long ulLength; - unsigned long ulWAVE; - unsigned long ulType; - unsigned long ulCount; - unsigned long ulLimit; - bool haveWaveHeader = false; - unsigned long waveSize = 0; - WAVEFORMAT waveFormat; - int toRead; - mb_int64_t fileLen = 0; - - source = fopen(filename.ascii(), "rb"); - if (source == NULL) - { -// errorString = string("File not found"); -// fclose(source); - cout << "File not found \n"; - return; - } - - fseek(source, 0, SEEK_END); - fileLen = ftell(source); - fseek(source, 0, SEEK_SET); - - if (fread(buffer, 1, 12, source) != 12) - { -// errorString = string("File is too short"); - cout << "File is to short \n"; - fclose(source); - return ; - } - - ulRIFF = (unsigned long)(((unsigned long *)buffer)[0]); - ulLength = (unsigned long)(((unsigned long *)buffer)[1]); - ulWAVE = (unsigned long)(((unsigned long *)buffer)[2]); - - if(ulRIFF != MAKEFOURCC('R', 'I', 'F', 'F') || - ulWAVE != MAKEFOURCC('W', 'A', 'V', 'E')) - { -// errorString = strdup("File is not in WAVE format"); - cout << "File is not WAVE \n"; - fclose(source); - return ; - } - - // Run through the bytes looking for the tags - ulCount = 0; - ulLimit = ulLength - 4; - while (ulCount < ulLimit && waveSize == 0) - { - if (fread(buffer, 1, 8, source) != 8) - { -// errorString = strdup("File is too short"); - cout << "File is to short \n"; - fclose(source); - return; - } - - ulType = (unsigned long)(((unsigned long *)buffer)[0]); - ulLength = (unsigned long)(((unsigned long *)buffer)[1]); - switch (ulType) - { - // format - case MAKEFOURCC('f', 'm', 't', ' '): - if (ulLength < sizeof(WAVEFORMAT)) - { -// errorString = strdup("File is too short"); - cout << "File is to short \n"; - fclose(source); - return ; - } - - if (fread(&waveFormat, 1, ulLength, source) != ulLength) - { -// errorString = strdup("File is too short"); - cout << "File is to short \n"; - fclose(source); - return ; - } - - if (waveFormat.wFormatTag != WAVE_FORMAT_PCM) - { -// errorString = strdup("Unsupported WAV format"); - cout << "Unsupported WAVE \n"; - fclose(source); - return ; - } - haveWaveHeader = true; - - ulCount += ulLength; - break; - - // data - case MAKEFOURCC('d', 'a', 't', 'a'): - waveSize = ulLength; - break; - - default: - fseek(source, ulLength, SEEK_CUR); - break; - - } - } - - - if (!haveWaveHeader) - { -// errorString = strdup("Could not find WAV header"); - cout << "Header nbot found \n"; - fclose(source); - return ; - } - - fileLen -= (mb_int64_t)ftell(source); - fileLen /= waveFormat.nChannels; - fileLen /= (waveFormat.nBlockAlign / waveFormat.nChannels); - - fileLen /= waveFormat.nSamplesPerSec; - - //on ne lit qu'un channel - //waveSize=fileLen; - data.resize(waveSize); - unsigned long pos=0; - - cout << "Weeee "<< waveSize <<"\n"; - - copyBuffer = (unsigned char*)malloc(BUFFER_LEN); - if (copyBuffer == NULL) - { -// errorString = strdup("Cannot allocate buffer space."); - return ; - } - - for(;;) - { - toRead = min(waveSize, (unsigned long)BUFFER_LEN); - if (toRead <= 0) - break; - - bytes = fread(copyBuffer, 1, toRead, source); - if (bytes <= 0) - break; - - for(uint f=0;f -#include -#include - -/** -@author Olivier Goffart -*/ -class KDE_EXPORT Sound{ -public: - Sound(); - ~Sound(); - - void load(const QString &filename); - void save(const QString &filename) const; - - unsigned int size() const - { - return data.size(); - } - - inline float at(int pos) const - { - return (float)(data.at(pos))/max; - } - - inline uint fs() const - { - return _fs; - } - - QVector data; - quint32 max; - uint _fs; -}; - -#endif diff --git a/khotkeys/libkhotkeysprivate/soundrecorder.cpp b/khotkeys/libkhotkeysprivate/soundrecorder.cpp deleted file mode 100644 index 4e0b43f3..00000000 --- a/khotkeys/libkhotkeysprivate/soundrecorder.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Olivier Goffart * - * ogoffart@kde.org * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include "soundrecorder.h" - -#include -#include -#include -#include - -#include "khotkeysglobal.h" - -namespace KHotKeys -{ - -SoundRecorder::create_ptr SoundRecorder::create_fun = NULL; - -bool SoundRecorder::init( QLibrary* lib ) -{ -#ifdef HAVE_ARTS - if( create_fun == NULL && lib != NULL ) - create_fun = (create_ptr) lib->symbol( "khotkeys_soundrecorder_create" ); -#endif -// kDebug() << "soundrecorder:" << create_fun << ":" << lib; - return create_fun != NULL; -} - -SoundRecorder* SoundRecorder::create( QObject* parent ) -{ -#ifdef HAVE_ARTS - if( create_fun != NULL ) - return create_fun( parent, name ); -#endif - return new SoundRecorder( parent ); -} - -SoundRecorder::SoundRecorder(QObject *parent) : QObject(parent) {} - -SoundRecorder::~SoundRecorder() -{ -} - -void SoundRecorder::start() -{ -} - -void SoundRecorder::stop() -{ -} - -void SoundRecorder::abort() -{ -} - - -Sound SoundRecorder::sound() -{ - Sound s; - return s; -} - -} - -#include "moc_soundrecorder.cpp" diff --git a/khotkeys/libkhotkeysprivate/soundrecorder.h b/khotkeys/libkhotkeysprivate/soundrecorder.h deleted file mode 100644 index a8afe7cf..00000000 --- a/khotkeys/libkhotkeysprivate/soundrecorder.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Olivier Goffart * - * ogoffart@kde.org * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef RECORDER_H -#define RECORDER_H - -#include -#include "sound.h" -#include - -#include - -namespace KHotKeys -{ - - - -/** -@author Olivier Goffart -*/ -class KDE_EXPORT SoundRecorder : public QObject -{ -Q_OBJECT -public: - static SoundRecorder* create( QObject* parent = 0 ); - virtual ~SoundRecorder(); - - virtual void start(); - virtual void stop(); - virtual void abort(); - virtual Sound sound(); - - static bool init( QLibrary* ); -signals: - void recorded(const Sound&); - -protected: - SoundRecorder(QObject *parent = 0); - typedef SoundRecorder* (*create_ptr)( QObject*, const char* ); -private: - static create_ptr create_fun; -}; - -} - -#endif diff --git a/khotkeys/libkhotkeysprivate/triggers/triggers.h b/khotkeys/libkhotkeysprivate/triggers/triggers.h index dbbaee30..3cd38ba9 100644 --- a/khotkeys/libkhotkeysprivate/triggers/triggers.h +++ b/khotkeys/libkhotkeysprivate/triggers/triggers.h @@ -28,7 +28,6 @@ #include #include "khotkeysglobal.h" -#include "voicesignature.h" #include "input.h" #include "windows_handler.h" @@ -351,50 +350,6 @@ class KDE_EXPORT GestureTrigger StrokePoints _pointdata; }; - - -// FIXME: SOUND -#if 0 -class KDE_EXPORT Voice_trigger - : public QObject, public Trigger - { - Q_OBJECT - typedef Trigger base; - public: - Voice_trigger( ActionData* data_P, const QString& Voice_P, const VoiceSignature & signature1_P, const VoiceSignature & signature2_P ); - Voice_trigger( KConfigGroup& cfg_P, ActionData* data_P ); - virtual ~Voice_trigger(); - virtual void cfg_write( KConfigGroup& cfg_P ) const; - virtual Trigger* copy( ActionData* data_P ) const; - virtual const QString description() const; - const QString& voicecode() const; - virtual void activate( bool activate_P ); - VoiceSignature voicesignature( int ech ) const; - - virtual TriggerType type() const { return SoundTrigger; } - public slots: - void handle_Voice( ); - private: - QString _voicecode; - VoiceSignature _voicesignature[2]; - }; -#endif - -// FIXME: SOUND -#if 0 -// Voice_trigger -inline -const QString& Voice_trigger::voicecode() const - { - return _voicecode; - } - -inline -VoiceSignature Voice_trigger::voicesignature(int ech) const - { - return _voicesignature[ech-1]; - } -#endif } // namespace KHotKeys diff --git a/khotkeys/libkhotkeysprivate/triggers/voice_trigger.cpp b/khotkeys/libkhotkeysprivate/triggers/voice_trigger.cpp deleted file mode 100644 index 366ab3d6..00000000 --- a/khotkeys/libkhotkeysprivate/triggers/voice_trigger.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - Copyright (C) 1999-2001 Lubos Lunak - Copyright (C) 2008 Michael Jansen - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "triggers.h" -#include "action_data.h" -#include "voices.h" -#include "windows.h" - -#include -#include - -namespace KHotKeys { - -Voice_trigger::Voice_trigger( ActionData* data_P, const QString &Voicecode_P, const VoiceSignature& signature1_P, const VoiceSignature& signature2_P ) -: Trigger( data_P ), _voicecode( Voicecode_P ) - { - _voicesignature[0]=signature1_P; - _voicesignature[1]=signature2_P; - } - -Voice_trigger::Voice_trigger( KConfigGroup& cfg_P, ActionData* data_P ) - : Trigger( cfg_P, data_P ) - { - _voicecode = cfg_P.readEntry( "Name" ); - _voicesignature[0].read( cfg_P , "Signature1" ); - _voicesignature[1].read( cfg_P , "Signature2" ); - } - -Voice_trigger::~Voice_trigger() - { - voice_handler->unregister_handler( this ); - } - -void Voice_trigger::cfg_write( KConfigGroup& cfg_P ) const - { - base::cfg_write( cfg_P ); - cfg_P.writeEntry( "Name", voicecode()); - cfg_P.writeEntry( "Type", "VOICE" ); // overwrites value set in base::cfg_write() - _voicesignature[0].write( cfg_P , "Signature1" ); - _voicesignature[1].write( cfg_P , "Signature2" ); - } - -Trigger* Voice_trigger::copy( ActionData* data_P ) const - { - kDebug() << "Voice_trigger::copy()"; - return new Voice_trigger( data_P ? data_P : data, voicecode(), voicesignature(1) , voicesignature(2) ); - } - -const QString Voice_trigger::description() const - { - return i18n( "Voice trigger: " ) + voicecode(); - } - -void Voice_trigger::handle_Voice( ) - { - windows_handler->set_action_window( 0 ); // use active window - data->execute(); - - } - -void Voice_trigger::activate( bool activate_P ) - { - if( activate_P && khotkeys_active()) - voice_handler->register_handler( this ); - else - voice_handler->unregister_handler( this ); - } - -} // namespace KHotKeys - diff --git a/khotkeys/libkhotkeysprivate/voices.cpp b/khotkeys/libkhotkeysprivate/voices.cpp deleted file mode 100644 index 4c9ee321..00000000 --- a/khotkeys/libkhotkeysprivate/voices.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/**************************************************************************** - - KHotKeys - - Copyright (C) 2005 Olivier Goffart - - Distributed under the terms of the GNU General Public License version 2. - -****************************************************************************/ - - -#include - -#include "voices.h" -#include "voicesignature.h" -#include "triggers.h" -#include "soundrecorder.h" - -#include -#include -#include - - -#include -#include -#include -#include - - -#include -#include - - - -namespace KHotKeys -{ - -Voice* voice_handler; - -Voice::Voice( bool enabled_P, QObject* parent_P ) - : QObject( parent_P) ,_enabled( enabled_P ), _recording( false ), _recorder(0) - { - assert( voice_handler == NULL ); - voice_handler = this; - - _kga=0L; - _timer=0L; - - kDebug() ; - - } - -Voice::~Voice() - { - kDebug() ; - enable( false ); - voice_handler = NULL; - } - - -void Voice::enable( bool enabled_P ) - { -#ifndef HAVE_ARTS - enabled_P = false; // never enabled when there's no support -#endif - if( _enabled == enabled_P ) - return; - _enabled = enabled_P; - _kga->setEnabled(enabled_P); - } - -void Voice::register_handler( Voice_trigger *trigger_P ) - { - if( !_references.contains( trigger_P )) - _references.append(trigger_P); - } - -void Voice::unregister_handler( Voice_trigger *trigger_P ) - { - _references.remove(trigger_P); - } - - -void Voice::record_start() -{ - kDebug() ; - if(!_recorder) - { - _recorder= SoundRecorder::create(this); - connect(_recorder, SIGNAL(recorded(Sound)), this, SLOT(slot_sound_recorded(Sound))); - } - - _recorder->start(); - _recording=true; -} - -void Voice::record_stop() -{ - if(!_recording) - return; - - kDebug() ; - delete _timer; - _timer=0L; - _recording=false; - if(_recorder) - _recorder->stop(); -} - - -void Voice::slot_sound_recorded(const Sound &sound_P) -{ - VoiceSignature signature(sound_P); - - Voice_trigger *trig=0L; - Voice_trigger *sec_trig=0L; - double minimum=800000; - double second_minimum=80000; - int got_count=0; - foreach(Voice_trigger *t, _references) - { - for(int ech=1; ech<=2 ; ech++) - { - double diff=VoiceSignature::diff(signature, t->voicesignature(ech)); - if(minimum>=diff) - { - second_minimum=minimum; - minimum=diff; - sec_trig=trig; - trig=t; - } - else if(second_minimum>=diff) - { - second_minimum=diff; - sec_trig=t; - } - if( diff < REJECT_FACTOR_DIFF ) - got_count++; - kDebug() << ( (diff < REJECT_FACTOR_DIFF) ? "+++" : "---" ) <voicecode() << ech << " : " << diff; - } - } -// double ecart_relatif=(second_minimum-minimum)/minimum; - -// kDebug() << ecart_relatif; - - if(trig) - kDebug() << "**** " << trig->voicecode() << " : " << minimum; - - -// if(trig && ecart_relatif > REJECT_FACTOR_ECART_REL) -// if(trig && got_count==1) - bool selected=trig && (got_count==1 || ( minimum < 1.5*REJECT_FACTOR_DIFF && trig==sec_trig ) ); - - if(selected) - { - trig->handle_Voice(); - } - -} - - -/*bool Voice::x11Event( XEvent* pEvent ) -{ - if( pEvent->type != XKeyPress && pEvent->type != XKeyRelease ) - return false; - - KKeyNative keyNative( pEvent ); - - //kDebug() << keyNative.key().toString(); - - if(_shortcut.contains(keyNative)) - { - if(pEvent->type == XKeyPress && !_recording ) - { - record_start(); - return true; - } - if(pEvent->type == XKeyRelease && _recording ) - { - record_stop(); - return true; - } - } - return false; -} - - -*/ - - -void Voice::set_shortcut( const KShortcut &shortcut) -{ - _shortcut = shortcut; - if( !_enabled ) - return; - if(!_kga) - { - _kga = new KAction(this); - _kga->setObjectName("khotkeys_voice"); - connect(_kga,SIGNAL(triggered(bool)) , this , SLOT(slot_key_pressed())); - } - _kga->setGlobalShortcut(shortcut); -} - -void Voice::slot_key_pressed() -{ - if( _recording ) - record_stop(); - else - { - record_start(); - if(!_timer) - { - _timer=new QTimer(this); - connect(_timer, SIGNAL(timeout()) , this, SLOT(slot_timeout())); - } - _timer->setSingleShot(true); - _timer->start(1000*20); - } -} - - -void Voice::slot_timeout() -{ - if(_recording && _recorder) - { - _recorder->abort(); - _recording=false; - } - _timer->deleteLater(); - _timer=0L; -} - - -QString Voice::isNewSoundFarEnough(const VoiceSignature& signature, const QString ¤tTrigger) -{ - Voice_trigger *trig=0L; - Voice_trigger *sec_trig=0L; - double minimum=800000; - double second_minimum=80000; - int got_count=0; - foreach (Voice_trigger *t , _references) - { - if(t->voicecode()==currentTrigger) - continue; - - for(int ech=1; ech<=2 ; ech++) - { - double diff=VoiceSignature::diff(signature, t->voicesignature(ech)); - if(minimum>=diff) - { - second_minimum=minimum; - minimum=diff; - sec_trig=trig; - trig=t; - } - else if(second_minimum>=diff) - { - second_minimum=diff; - sec_trig=t; - } - if( diff < REJECT_FACTOR_DIFF ) - got_count++; - kDebug() << ( (diff < REJECT_FACTOR_DIFF) ? "+++" : "---" ) <voicecode() << ech << " : " << diff; - } - } - - if(trig) - kDebug() << "**** " << trig->voicecode() << " : " << minimum; - - bool selected=trig && ((got_count==1 && minimum < REJECT_FACTOR_DIFF*0.7 ) || ( minimum < REJECT_FACTOR_DIFF && trig==sec_trig ) ); - return selected ? trig->voicecode() : QString(); -} - -bool Voice::doesVoiceCodeExists(const QString &vc) -{ - foreach (Voice_trigger *t , _references) - { - if(t->voicecode()==vc) - return true; - } - return false; -} - -} // namespace KHotKeys - -#include "moc_voices.cpp" diff --git a/khotkeys/libkhotkeysprivate/voices.h b/khotkeys/libkhotkeysprivate/voices.h deleted file mode 100644 index 9801a976..00000000 --- a/khotkeys/libkhotkeysprivate/voices.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** - - KHotKeys - - Copyright (C) 2005 Olivier Goffart - - Distributed under the terms of the GNU General Public License version 2. - -****************************************************************************/ - -#ifndef VOICES_H_ -#define VOICES_H_ - -#include -#include - -class Sound; -#include -class KAction; - -namespace KHotKeys -{ - -class Voice; -class SoundRecorder; - -class Voice_trigger; -class VoiceSignature; - - -class KDE_EXPORT Voice : public QObject - { - Q_OBJECT - public: - Voice( bool enabled_P, QObject* parent_P ); - virtual ~Voice(); - void enable( bool enable_P ); - - void register_handler( Voice_trigger* ); - void unregister_handler( Voice_trigger* ); -// bool x11Event( XEvent* e ); - - void set_shortcut( const KShortcut &k); - - /** - * return QString() is a new signature is far enough from others signature - * otherwise, return the stringn which match. - */ - QString isNewSoundFarEnough(const VoiceSignature& s, const QString& currentTrigger); - - bool doesVoiceCodeExists(const QString &s); - - public slots: - void record_start(); - void record_stop(); - - private slots: - void slot_sound_recorded( const Sound & ); - void slot_key_pressed(); - void slot_timeout(); - - signals: - void handle_voice( const QString &voice ); - private: - - bool _enabled; - bool _recording; - - QList _references; - SoundRecorder *_recorder; - - KShortcut _shortcut; - KAction *_kga; - - QTimer *_timer; - }; - - -KDE_EXPORT extern Voice* voice_handler; - -} // namespace KHotKeys - -#endif diff --git a/khotkeys/libkhotkeysprivate/voicesignature.cpp b/khotkeys/libkhotkeysprivate/voicesignature.cpp deleted file mode 100644 index e5c50644..00000000 --- a/khotkeys/libkhotkeysprivate/voicesignature.cpp +++ /dev/null @@ -1,423 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Olivier Goffart * - * ogoffart@kde.org * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "voicesignature.h" -#include "sound.h" -#include -#include - -#include -#ifdef PI -#undef PI -#endif -#define PI (2.0 * asin(1.0)) - - -#include -#include - -#undef Complex - -namespace KHotKeys -{ - - -inline static float ABS(float X) -{ - return (X>0) ? X : -X ; -} -inline static int MAX(int X , int Y) -{ - return (X>Y) ? X : Y ; -} -inline static int MIN(int X , int Y) -{ - return (X fft(const Sound& sound, unsigned int start, unsigned int stop) -{ - if(start>=stop || sound.size()==0) - return QVector(); - - //We need a sample with a size of a power of two - uint size=stop-start; - unsigned short log2size=0; - while( (1< size/4 || 1< sound.size() ) - { - log2size--; - diff=(1<sound.size()) - { - start2-= stop2 - sound.size(); - stop2=sound.size(); - if(start2<0) - { - stop2-=start2; - start2=0; - } - } - - //Generate an array to work in - QVector samples(size); - - //Fill it with samples in the "reversed carry" order - int rev_carry = 0; - for (uint f = 0; f < size - 1; f++) - { - samples[f]=sound.at(start2+rev_carry)* hamming(rev_carry, size); -// KDEBUG(rev_carry); - int mask = size>>1; // N / 2 - // add 1 backwards - while (rev_carry >= mask) - { - rev_carry -= mask; // turn off this bit - mask >>= 1; - } - rev_carry += mask; - } - samples[size-1]=sound.at(start2+size-1)*hamming(size-1, size); - - //FFT - for(uint level=0; level < log2size; level++) - { - for( int k=0; k< (size>>1) ; k++) - { - uint indice1 = (k << (level+1) ) % (size-1); // (k*2*2^l)%(N-1) - uint indice2 = indice1 + (1< result(size); - for(uint f=0;f VoiceSignature::fft(const Sound& sound, unsigned int start, unsigned int stop) -{ - return KHotKeys::fft(sound, start, stop); - /*QVector result(8000); - for(int f=0; f<8000;f++) - { - Complex c(0); - - for(uint x=start; xWINDOW_MINIMUM*unit) - isNoise=true; - - for(uint x=unit; xWINDOW_MINIMUM*unit && isNoise) - return false; - - stop=MIN(length,stop+WINDOW_MINIMUM_ECART); - start=MAX(0 ,start-WINDOW_MINIMUM_ECART); - - if(_start) - *_start=start; - if(_stop) - *_stop=stop; - return start fourrier=fft(sound, w_start,w_stop); - - temp_fft+=t.restart(); - - //MEL conversion - double mel_start=HZ_TO_MEL(FFT_RANGE_INF); - uint mel_stop=HZ_TO_MEL(FFT_RANGE_SUP); - - for(int four=0; four > VoiceSignature::pond; - - - -void VoiceSignature::write(KConfigGroup& cfg, const QString &key) const -{ - QStringList sl; - for(int x=0;x -#include -#include -#include - -class Sound; - - -#define WINDOW_MINIMUM 0.10 -#define WINDOW_MINIMUM_ECART 200 -#define WINDOW_NUMBER 7 -#define WINDOW_SUPER 0.43 -#define WINDOW_UNIT sound.fs()/4 -#define FOUR_NUMBER 7 -#define FOUR_SUPER 0 - - -#define FFT_RANGE_INF 370 -#define FFT_RANGE_SUP 2000 -// #define FFT_PONDERATION(f) ((double)log(1+(f))/log(10)) -#define FFT_PONDERATION(f) 1 - - -// theses settings are better in a 8000Hz fs -/*#define FFT_RANGE_INF 300 -#define FFT_RANGE_SUP 1500*/ - - -//#define REJECT_FACTOR_ECART_REL 0.5 -#define REJECT_FACTOR_DIFF 0.0018 - - - -#define HAMMING false - - - - -namespace KHotKeys -{ - - -/** -@author Olivier Goffart -*/ -class KDE_EXPORT VoiceSignature{ -public: - explicit VoiceSignature(const Sound& s); - - VoiceSignature(){} - ~VoiceSignature(); - - QMap > data; - - static QMap > pond; - - static float diff(const VoiceSignature &s1, const VoiceSignature &s2); - - - static int size1(); - static int size2(); - - - static QVector fft(const Sound& sound, unsigned int start, unsigned int stop); - static bool window(const Sound& sound, unsigned int *start, unsigned int *stop); - - void write(KConfigGroup& cfg, const QString &key) const; - void read(KConfigGroup& cfg, const QString &key); - - inline bool isNull() const - { - return data.isEmpty(); - } -}; - -} - -#endif