#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <math.h>
#include <stddef.h>
#include <algorithm>
#include <map>
#include <memory>
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/no_destructor.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/threading/sequence_bound.h"
#include "content/browser/speech/tts_platform_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/tts_controller.h"
#include "content/public/common/content_switches.h"
#include "library_loaders/libspeechd.h"
namespace content {
namespace {
struct SPDChromeVoice { … };
PlatformVoices;
constexpr int kInvalidUtteranceId = …;
constexpr int kInvalidMessageUid = …;
}
class TtsPlatformImplBackgroundWorker { … };
class TtsPlatformImplLinux : public TtsPlatformImpl { … };
void TtsPlatformImplBackgroundWorker::Initialize() { … }
void TtsPlatformImplBackgroundWorker::ProcessSpeech(
int utterance_id,
const std::string& parsed_utterance,
const std::string& lang,
float rate,
float pitch,
SPDChromeVoice voice,
base::OnceCallback<void(bool)> on_speak_finished) { … }
void TtsPlatformImplBackgroundWorker::Pause() { … }
void TtsPlatformImplBackgroundWorker::Resume() { … }
void TtsPlatformImplBackgroundWorker::StopSpeaking() { … }
void TtsPlatformImplBackgroundWorker::Shutdown() { … }
bool TtsPlatformImplBackgroundWorker::InitializeSpeechd() { … }
void TtsPlatformImplBackgroundWorker::InitializeVoices(PlatformVoices* voices) { … }
void TtsPlatformImplBackgroundWorker::OpenConnection() { … }
void TtsPlatformImplBackgroundWorker::CloseConnection() { … }
void TtsPlatformImplBackgroundWorker::OnSpeechEvent(int msg_id,
SPDNotificationType type) { … }
void TtsPlatformImplBackgroundWorker::SendTtsEvent(int utterance_id,
TtsEventType event_type,
int char_index,
int length) { … }
void TtsPlatformImplBackgroundWorker::NotificationCallback(
size_t msg_id,
size_t client_id,
SPDNotificationType type) { … }
void TtsPlatformImplBackgroundWorker::IndexMarkCallback(
size_t msg_id,
size_t client_id,
SPDNotificationType type,
char* index_mark) { … }
TtsPlatformImplLinux::TtsPlatformImplLinux()
: … { … }
bool TtsPlatformImplLinux::PlatformImplSupported() { … }
bool TtsPlatformImplLinux::PlatformImplInitialized() { … }
void TtsPlatformImplLinux::Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params,
base::OnceCallback<void(bool)> on_speak_finished) { … }
bool TtsPlatformImplLinux::StopSpeaking() { … }
void TtsPlatformImplLinux::Pause() { … }
void TtsPlatformImplLinux::Resume() { … }
bool TtsPlatformImplLinux::IsSpeaking() { … }
void TtsPlatformImplLinux::GetVoices(std::vector<VoiceData>* out_voices) { … }
void TtsPlatformImplLinux::Shutdown() { … }
void TtsPlatformImplLinux::OnInitialized(bool success, PlatformVoices voices) { … }
void TtsPlatformImplLinux::OnSpeakScheduled(
base::OnceCallback<void(bool)> on_speak_finished,
bool success) { … }
void TtsPlatformImplLinux::OnSpeakFinished(int utterance_id) { … }
void TtsPlatformImplLinux::ProcessSpeech(
int utterance_id,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params,
base::OnceCallback<void(bool)> on_speak_finished,
const std::string& parsed_utterance) { … }
TtsPlatformImplLinux* TtsPlatformImplLinux::GetInstance() { … }
TtsPlatformImpl* TtsPlatformImpl::GetInstance() { … }
}