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