Showing the changes to interface/src/scripting/TTSScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -37,6 +37,9 @@ TTSScriptingInterface::TTSScriptingInterface() { · 36 unmodified lines | |||
| 37 | if (FAILED(hr)) { | 37 | if (FAILED(hr)) { |
| 38 | qDebug() << "Can't set default voice."; | 38 | qDebug() << "Can't set default voice."; |
| 39 | } | 39 | } |
| 40 | |||
| 41 | _lastSoundAudioInjectorUpdateTimer.setSingleShot(true); | ||
| 42 | connect(&_lastSoundAudioInjectorUpdateTimer, &QTimer::timeout, this, &TTSScriptingInterface::updateLastSoundAudioInjector); | ||
| 40 | #endif | 43 | #endif |
| 41 | } | 44 | } |
| 42 | 45 | ||
| @@ -58,38 +61,22 @@ private: · 15 unmodified lines | |||
| 58 | }; | 61 | }; |
| 59 | #endif | 62 | #endif |
| 60 | 63 | ||
| 61 | void TTSScriptingInterface::testTone(const bool& alsoInject) { | 64 | const std::chrono::milliseconds INJECTOR_INTERVAL_MS = std::chrono::milliseconds(100); |
| 62 | QByteArray byteArray(480000, 0); | 65 | void TTSScriptingInterface::updateLastSoundAudioInjector() { |
| 63 | _lastSoundByteArray.resize(0); | 66 | if (_lastSoundAudioInjector) { |
| 64 | _lastSoundByteArray.resize(480000); | ||
| 65 | |||
| 66 | int32_t a = 0; | ||
| 67 | int16_t* samples = reinterpret_cast<int16_t*>(byteArray.data()); | ||
| 68 | for (a = 0; a < 240000; a++) { | ||
| 69 | int16_t temp = (glm::sin(glm::radians((float)a))) * 32768; | ||
| 70 | samples[a] = temp; | ||
| 71 | } | ||
| 72 | emit ttsSampleCreated(_lastSoundByteArray, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * 50, 96); | ||
| 73 | |||
| 74 | if (alsoInject) { | ||
| 75 | AudioInjectorOptions options; | 67 | AudioInjectorOptions options; |
| 76 | options.position = DependencyManager::get<AvatarManager>()->getMyAvatarPosition(); | 68 | options.position = DependencyManager::get<AvatarManager>()->getMyAvatarPosition(); |
| 77 | 69 | _lastSoundAudioInjector->setOptions(options); | |
| 78 | _lastSoundAudioInjector = AudioInjector::playSound(_lastSoundByteArray, options); | 70 | _lastSoundAudioInjectorUpdateTimer.start(INJECTOR_INTERVAL_MS); |
| 79 | } | 71 | } |
| 80 | } | 72 | } |
| 81 | 73 | ||
| 82 | void TTSScriptingInterface::speakText(const QString& textToSpeak, | 74 | void TTSScriptingInterface::speakText(const QString& textToSpeak) { |
| 83 | const int& newChunkSize, | ||
| 84 | const int& timerInterval, | ||
| 85 | const int& sampleRate, | ||
| 86 | const int& bitsPerSample, | ||
| 87 | const bool& alsoInject) { | ||
| 88 | #ifdef WIN32 | 75 | #ifdef WIN32 |
| 89 | WAVEFORMATEX fmt; | 76 | WAVEFORMATEX fmt; |
| 90 | fmt.wFormatTag = WAVE_FORMAT_PCM; | 77 | fmt.wFormatTag = WAVE_FORMAT_PCM; |
| 91 | fmt.nSamplesPerSec = sampleRate; | 78 | fmt.nSamplesPerSec = 24000; |
| 92 | fmt.wBitsPerSample = bitsPerSample; | 79 | fmt.wBitsPerSample = 16; |
| 93 | fmt.nChannels = 1; | 80 | fmt.nChannels = 1; |
| 94 | fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8; | 81 | fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8; |
| 95 | fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign; | 82 | fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign; |
| @@ -156,16 +143,17 @@ void TTSScriptingInterface::speakText(const QString& textToSpeak, · 60 unmodified lines | |||
| 156 | _lastSoundByteArray.resize(0); | 143 | _lastSoundByteArray.resize(0); |
| 157 | _lastSoundByteArray.append(buf1, dwSize); | 144 | _lastSoundByteArray.append(buf1, dwSize); |
| 158 | 145 | ||
| 159 | // Commented out because this doesn't work completely :) | 146 | AudioInjectorOptions options; |
| 160 | // Obviously, commenting this out isn't fit for production, but it's fine for a test PR | 147 | options.position = DependencyManager::get<AvatarManager>()->getMyAvatarPosition(); |
| 161 | //emit ttsSampleCreated(_lastSoundByteArray, newChunkSize, timerInterval); | ||
| 162 | 148 | ||
| 163 | if (alsoInject) { | 149 | if (_lastSoundAudioInjector) { |
| 164 | AudioInjectorOptions options; | 150 | _lastSoundAudioInjector->stop(); |
| 165 | options.position = DependencyManager::get<AvatarManager>()->getMyAvatarPosition(); | 151 | _lastSoundAudioInjectorUpdateTimer.stop(); |
| 166 | |||
| 167 | _lastSoundAudioInjector = AudioInjector::playSound(_lastSoundByteArray, options); | ||
| 168 | } | 152 | } |
| 153 | |||
| 154 | _lastSoundAudioInjector = AudioInjector::playSoundAndDelete(_lastSoundByteArray, options); | ||
| 155 | |||
| 156 | _lastSoundAudioInjectorUpdateTimer.start(INJECTOR_INTERVAL_MS); | ||
| 169 | #else | 157 | #else |
| 170 | qDebug() << "Text-to-Speech isn't currently supported on non-Windows platforms."; | 158 | qDebug() << "Text-to-Speech isn't currently supported on non-Windows platforms."; |
| 171 | #endif | 159 | #endif |
| @@ -174,7 +162,6 @@ void TTSScriptingInterface::speakText(const QString& textToSpeak, · 2 unmodified lines | |||
| 174 | void TTSScriptingInterface::stopLastSpeech() { | 162 | void TTSScriptingInterface::stopLastSpeech() { |
| 175 | if (_lastSoundAudioInjector) { | 163 | if (_lastSoundAudioInjector) { |
| 176 | _lastSoundAudioInjector->stop(); | 164 | _lastSoundAudioInjector->stop(); |
| 165 | _lastSoundAudioInjector = NULL; | ||
| 177 | } | 166 | } |
| 178 | |||
| 179 | emit clearTTSBuffer(); | ||
| 180 | } | 167 | } |