|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GinoPane\PHPolyglot\API\Implementation\TTS; |
|
4
|
|
|
|
|
5
|
|
|
use GinoPane\NanoRest\Request\RequestContext; |
|
6
|
|
|
use GinoPane\NanoRest\Exceptions\TransportException; |
|
7
|
|
|
use GinoPane\PHPolyglot\API\Response\TTS\TtsResponse; |
|
8
|
|
|
use GinoPane\PHPolyglot\API\Implementation\ApiAbstract; |
|
9
|
|
|
use GinoPane\PHPolyglot\Supplemental\Language\Language; |
|
10
|
|
|
use GinoPane\NanoRest\Response\ResponseContextAbstract; |
|
11
|
|
|
use GinoPane\NanoRest\Exceptions\ResponseContextException; |
|
12
|
|
|
use GinoPane\PHPolyglot\API\Supplemental\TTS\TtsAudioFormat; |
|
13
|
|
|
use GinoPane\PHPolyglot\Exception\BadResponseContextException; |
|
14
|
|
|
use GinoPane\PHPolyglot\Exception\MethodDoesNotExistException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Interface TtsApiInterface |
|
18
|
|
|
* |
|
19
|
|
|
* @author Sergey <Gino Pane> Karavay |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class TtsApiAbstract extends ApiAbstract implements TtsApiInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Gets TTS raw data, that can be saved afterwards |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $text |
|
27
|
|
|
* @param Language $language |
|
28
|
|
|
* @param TtsAudioFormat $format |
|
29
|
|
|
* @param array $additionalData |
|
30
|
|
|
* |
|
31
|
|
|
* @throws TransportException |
|
32
|
|
|
* @throws ResponseContextException |
|
33
|
|
|
* @throws BadResponseContextException |
|
34
|
|
|
* @throws MethodDoesNotExistException |
|
35
|
|
|
* |
|
36
|
|
|
* @return TtsResponse |
|
37
|
|
|
*/ |
|
38
|
|
|
public function textToSpeech( |
|
39
|
|
|
string $text, |
|
40
|
|
|
Language $language, |
|
41
|
|
|
TtsAudioFormat $format, |
|
42
|
|
|
array $additionalData = [] |
|
43
|
|
|
): TtsResponse { |
|
44
|
|
|
/** @var TtsResponse $response */ |
|
45
|
|
|
$response = $this->callApi(__FUNCTION__, func_get_args()); |
|
46
|
|
|
|
|
47
|
|
|
return $response; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Create request context for text-to-speech request |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $text |
|
54
|
|
|
* @param Language $language |
|
55
|
|
|
* @param TtsAudioFormat $format |
|
56
|
|
|
* @param array $additionalData |
|
57
|
|
|
* |
|
58
|
|
|
* @return RequestContext |
|
59
|
|
|
*/ |
|
60
|
|
|
abstract protected function createTextToSpeechContext( |
|
61
|
|
|
string $text, |
|
62
|
|
|
Language $language, |
|
63
|
|
|
TtsAudioFormat $format, |
|
64
|
|
|
array $additionalData = [] |
|
65
|
|
|
): RequestContext; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Process response of text-to-speech request and prepare valid response |
|
69
|
|
|
* |
|
70
|
|
|
* @param ResponseContextAbstract $context |
|
71
|
|
|
* |
|
72
|
|
|
* @return TtsResponse |
|
73
|
|
|
*/ |
|
74
|
|
|
abstract protected function prepareTextToSpeechResponse(ResponseContextAbstract $context): TtsResponse; |
|
75
|
|
|
} |
|
76
|
|
|
|