Showing the changes to interface/src/scripting/TTSScriptingInterface.h (1 of 5 files). Show all
Unified · Split
| @@ -0,0 +1,83 @@ | ||
| 1 | +// TTSScriptingInterface.h | |
| 2 | +// libraries/audio-client/src/scripting | |
| 3 | +// | |
| 4 | +// Created by Zach Fox on 2018-10-10. | |
| 5 | +// Copyright 2018 High Fidelity, Inc. | |
| 6 | +// | |
| 7 | +// Distributed under the Apache License, Version 2.0. | |
| 8 | +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
| 9 | +// | |
| 10 | + | |
| 11 | +#ifndef hifi_SpeechScriptingInterface_h | |
| 12 | +#define hifi_SpeechScriptingInterface_h | |
| 13 | + | |
| 14 | +#include <QtCore/QObject> | |
| 15 | +#include <DependencyManager.h> | |
| 16 | +#ifndef WIN32_LEAN_AND_MEAN | |
| 17 | +#define WIN32_LEAN_AND_MEAN | |
| 18 | +#endif | |
| 19 | +#include <sapi.h> // SAPI | |
| 20 | +#include <sphelper.h> // SAPI Helper | |
| 21 | +#include <AudioInjector.h> | |
| 22 | + | |
| 23 | +class TTSScriptingInterface : public QObject, public Dependency { | |
| 24 | + Q_OBJECT | |
| 25 | + | |
| 26 | +public: | |
| 27 | + TTSScriptingInterface(); | |
| 28 | + ~TTSScriptingInterface(); | |
| 29 | + | |
| 30 | + Q_INVOKABLE void testTone(const bool& alsoInject = false); | |
| 31 | + Q_INVOKABLE void speakText(const QString& textToSpeak, const bool& alsoInject = false); | |
| 32 | + Q_INVOKABLE void stopLastSpeech(); | |
| 33 | + | |
| 34 | +signals: | |
| 35 | + void ttsSampleCreated(QByteArray outputArray); | |
| 36 | + | |
| 37 | +private: | |
| 38 | + class CComAutoInit { | |
| 39 | + public: | |
| 40 | + // Initializes COM using CoInitialize. | |
| 41 | + // On failure, signals error using AtlThrow. | |
| 42 | + CComAutoInit() { | |
| 43 | + HRESULT hr = ::CoInitialize(NULL); | |
| 44 | + if (FAILED(hr)) { | |
| 45 | + ATLTRACE(TEXT("CoInitialize() failed in CComAutoInit constructor (hr=0x%08X).\n"), hr); | |
| 46 | + AtlThrow(hr); | |
| 47 | + } | |
| 48 | + } | |
| 49 | + | |
| 50 | + // Initializes COM using CoInitializeEx. | |
| 51 | + // On failure, signals error using AtlThrow. | |
| 52 | + explicit CComAutoInit(__in DWORD dwCoInit) { | |
| 53 | + HRESULT hr = ::CoInitializeEx(NULL, dwCoInit); | |
| 54 | + if (FAILED(hr)) { | |
| 55 | + ATLTRACE(TEXT("CoInitializeEx() failed in CComAutoInit constructor (hr=0x%08X).\n"), hr); | |
| 56 | + AtlThrow(hr); | |
| 57 | + } | |
| 58 | + } | |
| 59 | + | |
| 60 | + // Uninitializes COM using CoUninitialize. | |
| 61 | + ~CComAutoInit() { ::CoUninitialize(); } | |
| 62 | + | |
| 63 | + // | |
| 64 | + // Ban copy | |
| 65 | + // | |
| 66 | + private: | |
| 67 | + CComAutoInit(const CComAutoInit&); | |
| 68 | + }; | |
| 69 | + | |
| 70 | + // COM initialization and cleanup (must precede other COM related data members) | |
| 71 | + CComAutoInit m_comInit; | |
| 72 | + | |
| 73 | + // Text to speech engine | |
| 74 | + CComPtr<ISpVoice> m_tts; | |
| 75 | + | |
| 76 | + // Default voice token | |
| 77 | + CComPtr<ISpObjectToken> m_voiceToken; | |
| 78 | + | |
| 79 | + QByteArray _lastSoundByteArray; | |
| 80 | + AudioInjectorPointer _lastSoundByteArray; | |
| 81 | +}; | |
| 82 | + | |
| 83 | +#endif // hifi_SpeechScriptingInterface_h | |