Path: blob/master/platform/windows/tts_driver_onecore.h
46006 views
/**************************************************************************/1/* tts_driver_onecore.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "tts_driver.h"3334GODOT_GCC_WARNING_PUSH35GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")36GODOT_GCC_WARNING_IGNORE("-Wctor-dtor-privacy")37GODOT_GCC_WARNING_IGNORE("-Wshadow")38GODOT_GCC_WARNING_IGNORE("-Wstrict-aliasing")39GODOT_CLANG_WARNING_PUSH40GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")4142#include <winrt/Windows.Foundation.Collections.h>43#include <winrt/Windows.Foundation.Metadata.h>44#include <winrt/Windows.Media.Core.h>45#include <winrt/Windows.Media.Playback.h>46#include <winrt/Windows.Media.SpeechSynthesis.h>47#include <winrt/Windows.Storage.Streams.h>4849GODOT_GCC_WARNING_POP50GODOT_CLANG_WARNING_POP5152using namespace winrt::Windows::Foundation;53using namespace winrt::Windows::Foundation::Collections;54using namespace winrt::Windows::Foundation::Metadata;55using namespace winrt::Windows::Media::Core;56using namespace winrt::Windows::Media::Playback;57using namespace winrt::Windows::Media::SpeechSynthesis;58using namespace winrt::Windows::Storage::Streams;5960struct TTSUtterance;6162class TTSDriverOneCore : public TTSDriver {63List<TTSUtterance> queue;6465bool playing = false;66bool paused = false;67bool update_requested = false;6869int64_t id = -1;70Char16String string;71std::shared_ptr<MediaPlayer> media;72struct TrackData {73TimedMetadataTrack track;74winrt::event_token token{};75};76Vector<TrackData> tracks;77winrt::event_token token_s{};78winrt::event_token token_f{};79winrt::event_token token_e{};80int64_t offset = 0;8182void _dispose_current(bool p_silent = false, bool p_canceled = false);8384void _speech_cancel(int p_msg_id);85void _speech_end(int p_msg_id);86void _speech_index_mark(int p_msg_id, int p_index_mark);8788static TTSDriverOneCore *singleton;8990public:91virtual bool is_speaking() const override;92virtual bool is_paused() const override;93virtual Array get_voices() const override;9495virtual 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;96virtual void pause() override;97virtual void resume() override;98virtual void stop() override;99100virtual void process_events() override;101102virtual bool init() override;103104TTSDriverOneCore();105~TTSDriverOneCore();106};107108109