Windows TTS: Use HashMap instead of RBMap for ids

And fixup includes in other implementations.
This commit is contained in:
Rémi Verschelde 2023-04-11 15:54:06 +02:00
parent 6a65597569
commit 92b9806dcc
No known key found for this signature in database
GPG Key ID: C3336907360768E1
6 changed files with 18 additions and 15 deletions

View File

@ -32,6 +32,7 @@
#define TTS_ANDROID_H #define TTS_ANDROID_H
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/templates/hash_map.h"
#include "core/variant/array.h" #include "core/variant/array.h"
#include "servers/display_server.h" #include "servers/display_server.h"

View File

@ -38,8 +38,8 @@
#endif #endif
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/templates/hash_map.h"
#include "core/templates/list.h" #include "core/templates/list.h"
#include "core/templates/rb_map.h"
#include "core/variant/array.h" #include "core/variant/array.h"
#include "servers/display_server.h" #include "servers/display_server.h"

View File

@ -34,8 +34,8 @@
#include "core/os/thread.h" #include "core/os/thread.h"
#include "core/os/thread_safe.h" #include "core/os/thread_safe.h"
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/templates/hash_map.h"
#include "core/templates/list.h" #include "core/templates/list.h"
#include "core/templates/rb_map.h"
#include "core/variant/array.h" #include "core/variant/array.h"
#include "servers/display_server.h" #include "servers/display_server.h"

View File

@ -32,8 +32,8 @@
#define TTS_MACOS_H #define TTS_MACOS_H
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/templates/hash_map.h"
#include "core/templates/list.h" #include "core/templates/list.h"
#include "core/templates/rb_map.h"
#include "core/variant/array.h" #include "core/variant/array.h"
#include "servers/display_server.h" #include "servers/display_server.h"

View File

@ -36,15 +36,16 @@ void __stdcall TTS_Windows::speech_event_callback(WPARAM wParam, LPARAM lParam)
TTS_Windows *tts = TTS_Windows::get_singleton(); TTS_Windows *tts = TTS_Windows::get_singleton();
SPEVENT event; SPEVENT event;
while (tts->synth->GetEvents(1, &event, NULL) == S_OK) { while (tts->synth->GetEvents(1, &event, NULL) == S_OK) {
if (tts->ids.has(event.ulStreamNum)) { uint32_t stream_num = (uint32_t)event.ulStreamNum;
if (tts->ids.has(stream_num)) {
if (event.eEventId == SPEI_START_INPUT_STREAM) { if (event.eEventId == SPEI_START_INPUT_STREAM) {
DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_STARTED, tts->ids[event.ulStreamNum].id); DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_STARTED, tts->ids[stream_num].id);
} else if (event.eEventId == SPEI_END_INPUT_STREAM) { } else if (event.eEventId == SPEI_END_INPUT_STREAM) {
DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_ENDED, tts->ids[event.ulStreamNum].id); DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_ENDED, tts->ids[stream_num].id);
tts->ids.erase(event.ulStreamNum); tts->ids.erase(stream_num);
tts->_update_tts(); tts->_update_tts();
} else if (event.eEventId == SPEI_WORD_BOUNDARY) { } else if (event.eEventId == SPEI_WORD_BOUNDARY) {
const Char16String &string = tts->ids[event.ulStreamNum].string; const Char16String &string = tts->ids[stream_num].string;
int pos = 0; int pos = 0;
for (int i = 0; i < MIN(event.lParam, string.length()); i++) { for (int i = 0; i < MIN(event.lParam, string.length()); i++) {
char16_t c = string[i]; char16_t c = string[i];
@ -53,7 +54,7 @@ void __stdcall TTS_Windows::speech_event_callback(WPARAM wParam, LPARAM lParam)
} }
pos++; pos++;
} }
DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_BOUNDARY, tts->ids[event.ulStreamNum].id, pos - tts->ids[event.ulStreamNum].offset); DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_BOUNDARY, tts->ids[stream_num].id, pos - tts->ids[stream_num].offset);
} }
} }
} }
@ -106,7 +107,7 @@ void TTS_Windows::_update_tts() {
synth->SetRate(10.f * log10(message.rate) / log10(3.f)); synth->SetRate(10.f * log10(message.rate) / log10(3.f));
synth->Speak((LPCWSTR)ut.string.get_data(), flags, &stream_number); synth->Speak((LPCWSTR)ut.string.get_data(), flags, &stream_number);
ids[stream_number] = ut; ids[(uint32_t)stream_number] = ut;
queue.pop_front(); queue.pop_front();
} }
@ -230,9 +231,10 @@ void TTS_Windows::stop() {
SPVOICESTATUS status; SPVOICESTATUS status;
synth->GetStatus(&status, nullptr); synth->GetStatus(&status, nullptr);
if (ids.has(status.ulCurrentStream)) { uint32_t current_stream = (uint32_t)status.ulCurrentStream;
DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, ids[status.ulCurrentStream].id); if (ids.has(current_stream)) {
ids.erase(status.ulCurrentStream); DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, ids[current_stream].id);
ids.erase(current_stream);
} }
for (DisplayServer::TTSUtterance &message : queue) { for (DisplayServer::TTSUtterance &message : queue) {
DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, message.id); DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, message.id);

View File

@ -32,8 +32,8 @@
#define TTS_WINDOWS_H #define TTS_WINDOWS_H
#include "core/string/ustring.h" #include "core/string/ustring.h"
#include "core/templates/hash_map.h"
#include "core/templates/list.h" #include "core/templates/list.h"
#include "core/templates/rb_map.h"
#include "core/variant/array.h" #include "core/variant/array.h"
#include "servers/display_server.h" #include "servers/display_server.h"
@ -54,7 +54,7 @@ class TTS_Windows {
int offset; int offset;
int id; int id;
}; };
RBMap<ULONG, UTData> ids; HashMap<uint32_t, UTData> ids;
static void __stdcall speech_event_callback(WPARAM wParam, LPARAM lParam); static void __stdcall speech_event_callback(WPARAM wParam, LPARAM lParam);
void _update_tts(); void _update_tts();