Last active
January 23, 2016 11:42
-
-
Save PonDad/81f24b6a4b038c73fe72 to your computer and use it in GitHub Desktop.
Voice Text Web API をPHPでシンプルに利用する。 ref: http://qiita.com/PonDad/items/9ec7813536f350a1023e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'voicetext.php'; | |
?> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>VoiceTextWebAPI-PHP</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css" /> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> | |
<h1 id="title" class="text-center h3">VoiceTextWebAPI-PHP</a></h1> | |
<article> | |
<div id="content" class="well"> | |
<p> | |
<?php | |
print('' .htmlspecialchars($_REQUEST['input_text'], ENT_QUOTES)); | |
?> | |
</p> | |
<br> | |
</div> | |
<div id="box" > | |
<form id="form" name="form" action="index.php" method="POST" /> | |
<input id="input_text" type="text" class="form-control" placeholder="Text input" name="input_text" value="" /> | |
<br> | |
<button type="submit" class="btn btn-default"><i class="fa fa-volume-up"></i> Voice Speech</button> | |
</form> | |
</div> | |
<audio id="voice" src="voice.wav"><audio> | |
</article> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script> | |
<script src="main.js"></script> | |
</body> | |
</html> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("document").ready(function() { | |
$("button").click(function() { | |
$("#input_text").value = text; | |
}); | |
$("#voice").play(); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import url(//fonts.googleapis.com/earlyaccess/notosansjapanese.css); | |
body { | |
font-family: 'Noto Sans Japanese', serif; | |
} | |
article{ | |
margin: 20px; | |
} | |
#content{ | |
width:300px;; | |
height: 60px;; | |
border-radius: 4px; | |
margin: 0 auto; | |
margin-bottom: 20px; | |
padding: 10px; | |
} | |
#box{ | |
width:300px; | |
margin: 0 auto; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "https://api.voicetext.jp/v1/tts"); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); | |
$authorized = "APIキー:"; | |
curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_BASIC); | |
curl_setopt($ch,CURLOPT_USERPWD,$authorized); | |
$post_array = array("text" => $_POST['input_text'], "speaker" => "haruka", "emotion" => "happiness", "pitch" => "80", "emotion_level" => "4"); | |
$postdata = ""; | |
foreach ($post_array as $key => $val) { | |
$postdata.= urlencode($key) . '=' . urlencode($val) . '&'; | |
} | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); | |
$output = curl_exec($ch); | |
curl_close($ch); | |
$fp = fopen("voice.wav", "w"); | |
fwrite($fp, $output); | |
fclose($fp); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment