TtsApiAbstract::textToSpeech()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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