-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvoice.php
41 lines (32 loc) · 1.08 KB
/
voice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
$key = parse_ini_file("api.ini",true)["docomo"]["key"];
if( isset($_GET["text"]) ){
$text = $_GET["text"];
$fname = "voice/".md5($text);
// ローカルファイルが存在するか確認
if( file_exists($fname) ){
echo file_get_contents($fname);
}else{
$text = $_GET["text"];
$apiUrl = "https://api.apigw.smt.docomo.ne.jp/voiceText/v1/textToSpeech?APIKEY=".$key;
//echo $apiUrl;
$header = [
"Content-Type: application/x-www-form-urlencoded"
];
$content = http_build_query([
"text"=>$text,
"speaker"=>"hikari"
]);
$context = [
"http"=>[
"method"=>"POST",
"header"=>implode("¥r¥n",$header),
"content"=>$content
]
];
$response = file_get_contents($apiUrl,false,stream_context_create($context));
$contents = '<audio autoplay src="data:audio/wav;base64,'.base64_encode($response).'"/>';
echo $contents;
file_put_contents($fname,$contents);
}
}