Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/windows/tts_driver_onecore.h
46006 views
1
/**************************************************************************/
2
/* tts_driver_onecore.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "tts_driver.h"
34
35
GODOT_GCC_WARNING_PUSH
36
GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")
37
GODOT_GCC_WARNING_IGNORE("-Wctor-dtor-privacy")
38
GODOT_GCC_WARNING_IGNORE("-Wshadow")
39
GODOT_GCC_WARNING_IGNORE("-Wstrict-aliasing")
40
GODOT_CLANG_WARNING_PUSH
41
GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")
42
43
#include <winrt/Windows.Foundation.Collections.h>
44
#include <winrt/Windows.Foundation.Metadata.h>
45
#include <winrt/Windows.Media.Core.h>
46
#include <winrt/Windows.Media.Playback.h>
47
#include <winrt/Windows.Media.SpeechSynthesis.h>
48
#include <winrt/Windows.Storage.Streams.h>
49
50
GODOT_GCC_WARNING_POP
51
GODOT_CLANG_WARNING_POP
52
53
using namespace winrt::Windows::Foundation;
54
using namespace winrt::Windows::Foundation::Collections;
55
using namespace winrt::Windows::Foundation::Metadata;
56
using namespace winrt::Windows::Media::Core;
57
using namespace winrt::Windows::Media::Playback;
58
using namespace winrt::Windows::Media::SpeechSynthesis;
59
using namespace winrt::Windows::Storage::Streams;
60
61
struct TTSUtterance;
62
63
class TTSDriverOneCore : public TTSDriver {
64
List<TTSUtterance> queue;
65
66
bool playing = false;
67
bool paused = false;
68
bool update_requested = false;
69
70
int64_t id = -1;
71
Char16String string;
72
std::shared_ptr<MediaPlayer> media;
73
struct TrackData {
74
TimedMetadataTrack track;
75
winrt::event_token token{};
76
};
77
Vector<TrackData> tracks;
78
winrt::event_token token_s{};
79
winrt::event_token token_f{};
80
winrt::event_token token_e{};
81
int64_t offset = 0;
82
83
void _dispose_current(bool p_silent = false, bool p_canceled = false);
84
85
void _speech_cancel(int p_msg_id);
86
void _speech_end(int p_msg_id);
87
void _speech_index_mark(int p_msg_id, int p_index_mark);
88
89
static TTSDriverOneCore *singleton;
90
91
public:
92
virtual bool is_speaking() const override;
93
virtual bool is_paused() const override;
94
virtual Array get_voices() const override;
95
96
virtual void speak(const String &p_text, const String &p_voice, int p_volume = 50, float p_pitch = 1.f, float p_rate = 1.f, int64_t p_utterance_id = 0, bool p_interrupt = false) override;
97
virtual void pause() override;
98
virtual void resume() override;
99
virtual void stop() override;
100
101
virtual void process_events() override;
102
103
virtual bool init() override;
104
105
TTSDriverOneCore();
106
~TTSDriverOneCore();
107
};
108
109