Google_tts   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A speak() 0 22 2
1
<?php
2
3
namespace JarvisPHP\Speakers;
4
5
/**
6
 * Wrapper class for using GoogleTTS as tts
7
 *
8
 * @author Stefano Bianchini
9
 * @website http://www.stefanobianchini.net
10
 */
11
class Google_tts {
12
    
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
36
}
37