blob: d28da47441dedc1b5fcaf1b664517b201866ec91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/*
* Copyright 2024 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#pragma once
#include <string>
#include "audio/fatfs_stream_factory.hpp"
#include "codec.hpp"
#include "drivers/pcm_buffer.hpp"
#include "tasks.hpp"
namespace tts {
/*
* A TTS Player is the output stage of the TTS pipeline. It receives a stream
* of filenames that should be played, and handles decoding these files and
* sending them to the output buffer.
*/
class Player {
public:
Player(tasks::WorkerPool&, drivers::PcmBuffer&, audio::FatfsStreamFactory&);
auto playFile(const std::string& text, const std::string& path) -> void;
// Not copyable or movable.
Player(const Player&) = delete;
Player& operator=(const Player&) = delete;
private:
tasks::WorkerPool& bg_;
audio::FatfsStreamFactory& stream_factory_;
drivers::PcmBuffer& output_;
std::mutex new_stream_mutex_;
std::atomic<bool> stream_playing_;
std::atomic<bool> stream_cancelled_;
auto openAndDecode(const std::string& text, const std::string& path) -> void;
auto decodeToSink(const codecs::ICodec::OutputFormat&,
std::unique_ptr<codecs::ICodec>) -> void;
};
} // namespace tts
|