-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
59 lines (56 loc) · 2.26 KB
/
index.html
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>讯飞语音web api demo</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-CCTZv2q9I9m3UOxRLaJneXrrqKwUNOzZ6NGEUMwHtShDJ+nCoiXJCAgi05KfkLGY" crossorigin="anonymous">
</head>
<body>
<div>
<audio controls autoplay></audio>
<button class="pure-button" onclick="startRecording()">录音</button>
<button class="pure-button" onclick="stopRecording()">停止</button>
<button class="pure-button" onclick="playRecording()">播放</button>
<button class="pure-button" onclick="uploadAudio()">提交</button>
</div>
<script type="text/javascript" src="hz.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
<script>
var recorder;
var audio = document.querySelector('audio');
function startRecording() {
HZRecorder.get(function (rec) {
recorder = rec;
recorder.start();
});
}
function stopRecording() {
recorder.stop();
}
function playRecording() {
recorder.play(audio);
}
function uploadAudio() {
recorder.upload("http://api.xfyun.cn/v1/service/v1/iat", function (state, e) {
switch (state) {
case 'uploading':
//var percentComplete = Math.round(e.loaded * 100 / e.total) + '%';
break;
case 'ok':
//alert(e.target.responseText);
//alert("上传成功");
window.location.href="VideoSearchServlet.do";
break;
case 'error':
alert("上传失败");
break;
case 'cancel':
alert("上传被取消");
break;
}
});
}
</script>
</body>
</html>