summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2023-04-11 15:54:06 +0200
committerYuri Sizov <yuris@humnom.net>2023-04-24 16:28:24 +0200
commiteffefe9feb1013312fdbe9cbae24828807cddd29 (patch)
tree8580603f0b5fa6d38eed096afd59429d9611c319 /platform
parent7e482f420d19bb4318f3ca448b014177b4f6baa4 (diff)
Windows TTS: Use HashMap instead of RBMap for ids
And fixup includes in other implementations. (cherry picked from commit 92b9806dcc98bc5ffbee6a7ca11090a926df0b3a)
Diffstat (limited to 'platform')
-rw-r--r--platform/android/tts_android.h1
-rw-r--r--platform/ios/tts_ios.h2
-rw-r--r--platform/linuxbsd/tts_linux.h2
-rw-r--r--platform/macos/tts_macos.h2
-rw-r--r--platform/windows/tts_windows.cpp22
-rw-r--r--platform/windows/tts_windows.h4
6 files changed, 18 insertions, 15 deletions
diff --git a/platform/android/tts_android.h b/platform/android/tts_android.h
index 8e3bfccbdb..8e00ac5000 100644
--- a/platform/android/tts_android.h
+++ b/platform/android/tts_android.h
@@ -32,6 +32,7 @@
#define TTS_ANDROID_H
#include "core/string/ustring.h"
+#include "core/templates/hash_map.h"
#include "core/variant/array.h"
#include "servers/display_server.h"
diff --git a/platform/ios/tts_ios.h b/platform/ios/tts_ios.h
index 2d104de8ae..7f9d30b22b 100644
--- a/platform/ios/tts_ios.h
+++ b/platform/ios/tts_ios.h
@@ -38,8 +38,8 @@
#endif
#include "core/string/ustring.h"
+#include "core/templates/hash_map.h"
#include "core/templates/list.h"
-#include "core/templates/rb_map.h"
#include "core/variant/array.h"
#include "servers/display_server.h"
diff --git a/platform/linuxbsd/tts_linux.h b/platform/linuxbsd/tts_linux.h
index 4134f8fa2f..651a64d9d6 100644
--- a/platform/linuxbsd/tts_linux.h
+++ b/platform/linuxbsd/tts_linux.h
@@ -34,8 +34,8 @@
#include "core/os/thread.h"
#include "core/os/thread_safe.h"
#include "core/string/ustring.h"
+#include "core/templates/hash_map.h"
#include "core/templates/list.h"
-#include "core/templates/rb_map.h"
#include "core/variant/array.h"
#include "servers/display_server.h"
diff --git a/platform/macos/tts_macos.h b/platform/macos/tts_macos.h
index 2153a4c692..35205bd1ae 100644
--- a/platform/macos/tts_macos.h
+++ b/platform/macos/tts_macos.h
@@ -32,8 +32,8 @@
#define TTS_MACOS_H
#include "core/string/ustring.h"
+#include "core/templates/hash_map.h"
#include "core/templates/list.h"
-#include "core/templates/rb_map.h"
#include "core/variant/array.h"
#include "servers/display_server.h"
diff --git a/platform/windows/tts_windows.cpp b/platform/windows/tts_windows.cpp
index 3a143d0ecb..54ab93ee01 100644
--- a/platform/windows/tts_windows.cpp
+++ b/platform/windows/tts_windows.cpp
@@ -36,15 +36,16 @@ void __stdcall TTS_Windows::speech_event_callback(WPARAM wParam, LPARAM lParam)
TTS_Windows *tts = TTS_Windows::get_singleton();
SPEVENT event;
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) {
- 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) {
- DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_ENDED, tts->ids[event.ulStreamNum].id);
- tts->ids.erase(event.ulStreamNum);
+ DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_ENDED, tts->ids[stream_num].id);
+ tts->ids.erase(stream_num);
tts->_update_tts();
} 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;
for (int i = 0; i < MIN(event.lParam, string.length()); i++) {
char16_t c = string[i];
@@ -53,7 +54,7 @@ void __stdcall TTS_Windows::speech_event_callback(WPARAM wParam, LPARAM lParam)
}
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->Speak((LPCWSTR)ut.string.get_data(), flags, &stream_number);
- ids[stream_number] = ut;
+ ids[(uint32_t)stream_number] = ut;
queue.pop_front();
}
@@ -230,9 +231,10 @@ void TTS_Windows::stop() {
SPVOICESTATUS status;
synth->GetStatus(&status, nullptr);
- if (ids.has(status.ulCurrentStream)) {
- DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, ids[status.ulCurrentStream].id);
- ids.erase(status.ulCurrentStream);
+ uint32_t current_stream = (uint32_t)status.ulCurrentStream;
+ if (ids.has(current_stream)) {
+ DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, ids[current_stream].id);
+ ids.erase(current_stream);
}
for (DisplayServer::TTSUtterance &message : queue) {
DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, message.id);
diff --git a/platform/windows/tts_windows.h b/platform/windows/tts_windows.h
index f0538a097c..33b597c612 100644
--- a/platform/windows/tts_windows.h
+++ b/platform/windows/tts_windows.h
@@ -32,8 +32,8 @@
#define TTS_WINDOWS_H
#include "core/string/ustring.h"
+#include "core/templates/hash_map.h"
#include "core/templates/list.h"
-#include "core/templates/rb_map.h"
#include "core/variant/array.h"
#include "servers/display_server.h"
@@ -54,7 +54,7 @@ class TTS_Windows {
int offset;
int id;
};
- RBMap<ULONG, UTData> ids;
+ HashMap<uint32_t, UTData> ids;
static void __stdcall speech_event_callback(WPARAM wParam, LPARAM lParam);
void _update_tts();