YandexFree   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B synthesize() 0 25 3
A getUri() 0 4 1
1
<?php
2
/**
3
 *
4
 * PHP version 5.5
5
 *
6
 * @author  Sergey V.Kuzin <[email protected]>
7
 * @license MIT
8
 */
9
namespace TTS;
10
11
use TTS\Traits\OnlineTrait;
12
13
class YandexFree extends TextToSpeechAbstract
14
{
15
    use OnlineTrait;
16
17
    protected $driver = 'YandexFree';
18
19
    protected $vote = 'female';
20
21
    /**
22
     * @param $text
23
     * @param $outFile
24
     * @return bool
25
     */
26
    protected function synthesize($text, $outFile)
27
    {
28
        $result = false;
29
        $sp = new \TTS\Helper\SplitterText();
30
        $text = iconv('UTF-8', 'UTF-8', $text);
31
32
        $lines = $sp->split($text, 512);
33
        $content = '';
34
        foreach ($lines as $line) {
35
            $query = [
36
                'quality'   => 'hi',
37
                'text'      => $line,
38
                'format'    => 'mp3',
39
                'lang'      => 'ru_RU',
40
                'platform'  => 'web',
41
                'application' => 'translate'
42
            ];
43
            $content .= $this->reguestGet($query);
44
        }
45
        if (strlen($content) > 0) {
46
            $result = true;
47
            file_put_contents($outFile, $content);
48
        }
49
        return $result;
50
    }
51
52
    protected function getUri()
53
    {
54
        return 'https://tts.voicetech.yandex.net/tts';
55
    }
56
}
57