Conditions | 5 |
Paths | 10 |
Total Lines | 40 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | public function say(Action $action) |
||
11 | { |
||
12 | $args = json_decode($action->getArguments(), true); |
||
13 | |||
14 | if (isset($this->parameters['text'])) { |
||
15 | $text = $this->parameters['text']; |
||
16 | } else { |
||
17 | $text = $args['text']; |
||
18 | } |
||
19 | |||
20 | if (!$text) { |
||
21 | return; |
||
22 | } |
||
23 | |||
24 | $textKey = md5($text); |
||
25 | |||
26 | if (!file_exists($this->getContainer()->getParameter('kernel.cache_dir').'/voice')) { |
||
27 | mkdir($this->getContainer()->getParameter('kernel.cache_dir').'/voice'); |
||
28 | } |
||
29 | |||
30 | $file = $this->getContainer()->getParameter('kernel.cache_dir').'/voice/'.$textKey.'.mp3'; |
||
31 | |||
32 | $result = 'Played from cache'; |
||
33 | |||
34 | if (!file_exists($file)) { |
||
35 | $res = file_get_contents( |
||
36 | "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q=". |
||
37 | urlencode($text)."&tl=De_de" |
||
38 | ); |
||
39 | file_put_contents($file, $res); |
||
40 | |||
41 | $result = 'Saved in cache'; |
||
42 | } |
||
43 | |||
44 | $res = exec('which mplayer'); |
||
45 | |||
46 | exec($res." -really-quiet -noconsolecontrols ".$file." >/dev/null 2>&1"); |
||
47 | |||
48 | return $result; |
||
49 | } |
||
50 | } |
||
51 |