Conditions | 2 |
Paths | 2 |
Total Lines | 22 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
13 | public static function speak($sentence) { |
||
14 | |||
15 | //Do not request a new mp3 if it exists in cache folder |
||
16 | if(!file_exists(_JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3')) { |
||
17 | $curl = curl_init(); |
||
18 | |||
19 | curl_setopt_array($curl, array( |
||
20 | CURLOPT_RETURNTRANSFER => 1, |
||
21 | CURLOPT_URL => 'http://translate.google.com/translate_tts?ie=UTF-8&client=t&tl='._LANGUAGE.'&q='.urlencode($sentence), |
||
22 | CURLOPT_USERAGENT => 'stagefright/1.2 (Linux;Android 5.0)', |
||
23 | CURLOPT_REFERER => 'http://translate.google.com/' |
||
24 | )); |
||
25 | |||
26 | $resp = curl_exec($curl); |
||
27 | |||
28 | curl_close($curl); |
||
29 | |||
30 | file_put_contents(_JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3', $resp); |
||
31 | } |
||
32 | |||
33 | exec('aplay '._JARVISPHP_ROOT_PATH.'/Speakers/cache/'.md5($sentence).'.mp3'); |
||
34 | } |
||
35 | |||
37 |