1
|
|
|
<?php |
2
|
|
|
namespace TTS\Driver; |
3
|
|
|
|
4
|
|
|
use GuzzleHttp\Exception\RequestException; |
5
|
|
|
|
6
|
|
|
abstract class AbstractAdapter |
7
|
|
|
{ |
8
|
|
|
const DEFAULT_LANG = 'en_GB'; |
9
|
|
|
|
10
|
|
|
protected $name = null; |
11
|
|
|
protected $voice = null; |
12
|
|
|
/** @var \GuzzleHttp\Client $client */ |
13
|
|
|
protected $client = null; |
14
|
|
|
|
15
|
|
|
protected $language = null; |
16
|
|
|
protected $speed = null; |
17
|
|
|
|
18
|
|
|
private $debug = false; |
19
|
|
|
|
20
|
|
|
protected $languageMap = [ |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
public function __construct($language = self::DEFAULT_LANG, $speed = '0.5') |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
if ($this->validateLanguage($language)) { |
27
|
|
|
throw new \Exception('The language is not supported'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$this->client = new \GuzzleHttp\Client(); |
31
|
|
|
$this->language = $this->languageMap[$language]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function setLanguage($language) |
35
|
|
|
{ |
36
|
|
|
if ($this->validateLanguage($language)) { |
37
|
|
|
throw new \Exception('The language is not supported'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$this->language = $this->languageMap[$language]; |
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function validateLanguage($language) |
45
|
|
|
{ |
46
|
|
|
return !array_key_exists($language, $this->languageMap); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getLanguage() |
50
|
|
|
{ |
51
|
|
|
return $this->language; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function setSpeed($speed) |
55
|
|
|
{ |
56
|
|
|
$this->speed = $speed; |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getSpeed() |
61
|
|
|
{ |
62
|
|
|
return $this->speed; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getName() |
66
|
|
|
{ |
67
|
|
|
return $this->name; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getVoice() |
71
|
|
|
{ |
72
|
|
|
return $this->voice; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function reguestGet($params) |
76
|
|
|
{ |
77
|
|
|
$headers = [ |
78
|
|
|
'User-Agent' => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.872.0 Safari/535.2' |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
try { |
82
|
|
|
$response = $this->client->get($this->getUri(), ['debug' => $this->debug, 'query' => $params, 'headers' => $headers]); |
83
|
|
|
} catch (RequestException $e) { |
84
|
|
|
echo $e->getMessage(); |
85
|
|
|
|
86
|
|
|
if ($e->hasResponse()) { |
|
|
|
|
87
|
|
|
} |
88
|
|
|
die('error'); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
return $response->getBody()->getContents(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
abstract public function getUri(); |
94
|
|
|
abstract public function make($text, $fileName); |
95
|
|
|
} |
96
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.