-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample.js
More file actions
executable file
·141 lines (112 loc) · 4.12 KB
/
sample.js
File metadata and controls
executable file
·141 lines (112 loc) · 4.12 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
(function() {
"use strict";
/* Recorder */
var audio_context;
var recorder;
/* UI components */
var button;
var buttonEnd;
var ul;
var interval;
/* Set up the Recorder */
window.onload = function init() {
try {
// webkit shim
window.AudioContext = window.AudioContext || window.webkitAudioContext;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
window.URL = window.URL || window.webkitURL;
console.log("windows", window);
audio_context = new AudioContext;
console.log("audio context", audio_context);
console.log('Audio context set up.');
console.log('navigator.getUserMedia ' + (navigator.getUserMedia ? 'available.' : 'not present!'));
} catch (e) {
console.log("ERROR", e);
}
navigator.getUserMedia({audio: true}, startUserMedia, function(e) {
console.log('No live audio input: ' + e);
});
};
// The initialize function is run each time the page is loaded.
// Office.initialize = function (reason) {
$(document).ready(function () {
// Use this to check whether the new API is supported in the Word client.
// if (Office.context.requirements.isSetSupported("WordApi", "1.1")) {
console.log('This code is using Word 2016 or greater.');
// Init UI Components
button = $('#start');
buttonEnd = $('#end');
ul = $('#recordingslist');
// on click listeners
button.click(function() {
button.html('Save');
startListening();
});
buttonEnd.click(function() {
button.html('Start Listening');
buttonEnd.html('End Listening');
endListening();
});
// }
});
// };
function startUserMedia(stream) {
var input = audio_context.createMediaStreamSource(stream);
console.log('Media stream created.');
// Uncomment if you want the audio to feedback directly
//input.connect(audio_context.destination);
//__log('Input connected to audio context destination.');
recorder = new Recorder(input);
console.log('Recorder initialised.');
}
function startListening() {
recorder && recorder.record();
interval = setInterval(function() {
createDownloadLink();
setTimeout(function(){
console.log("Restart the recording");
recorder.clear();
recorder && recorder.record();
}, 1000);
}, 6000);
button.disabled = true;
console.log('Recording...');
}
function endListening() {
recorder && recorder.stop();
buttonEnd.disabled = true;
console.log('Stopped recording.');
clearInterval(interval);
// create WAV download link using audio data blob
// createDownloadLink();
recorder.clear();
}
// create WAV download link using audio data blob
function createDownloadLink() {
recorder && recorder.exportWAV(function(blob) {
var url = URL.createObjectURL(blob);
var li = document.createElement('li');
var au = document.createElement('audio');
var hf = document.createElement('a');
console.log("url", url);
au.controls = true;
au.src = url;
console.log("au", au);
hf.href = url;
hf.download = new Date().toISOString() + '.wav';
hf.innerHTML = hf.download;
li.appendChild(au);
li.appendChild(hf);
});
}
// EndPoint https://speech.platform.bing.com/synthesize
function callTextToSpeechAPI() {
var request = new XMLHttpRequest();
request.open("POST", 'https://speech.platform.bing.com/synthesize', true);
request.onreadystatechange = function() {
if (request.readyState === 4 && request.status === 200)
console.log(request.responseText);
}
request.send(null);
}
})();