| Conditions | 5 |
| Paths | 10 |
| Total Lines | 38 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 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("http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q=". |
||
| 36 | urlencode($text)."&tl=De_de"); |
||
| 37 | file_put_contents($file, $res); |
||
| 38 | |||
| 39 | $result= 'Saved in cache'; |
||
| 40 | } |
||
| 41 | |||
| 42 | $res = exec('which mplayer'); |
||
| 43 | |||
| 44 | exec($res." -really-quiet -noconsolecontrols ".$file); |
||
| 45 | |||
| 46 | return $result; |
||
| 47 | } |
||
| 48 | } |
||
| 49 |