質問編集履歴
2
サーバ処理以外のロジック削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,12 +25,6 @@
|
|
25
25
|
var fs = require('fs');
|
26
26
|
|
27
27
|
var http = require('http');
|
28
|
-
|
29
|
-
var io = require('socket.io').listen(http);
|
30
|
-
|
31
|
-
var WavEncoder = require('wav-encoder');
|
32
|
-
|
33
|
-
var webclient = require("request");
|
34
28
|
|
35
29
|
|
36
30
|
|
1
出してはいけない情報削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,84 +66,6 @@
|
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
-
// 録音終了を検知して処理を開始
|
70
|
-
|
71
|
-
io.on('connection', function(socket) {
|
72
|
-
|
73
|
-
socket.on('stop', function(data) {
|
74
|
-
|
75
|
-
console.log('Socket Cath');
|
76
|
-
|
77
|
-
exportWAV(data, 11025);
|
78
|
-
|
79
|
-
});
|
80
|
-
|
81
|
-
});
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
// wav変換~Empath APIにデータを投げる処理
|
86
|
-
|
87
|
-
function exportWAV(data, sampleRate) {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
let audioData = {
|
92
|
-
|
93
|
-
sampleRate: sampleRate,
|
94
|
-
|
95
|
-
channelData: [
|
96
|
-
|
97
|
-
new Float32Array(11025).map(() => Math.random() - 0.5)
|
98
|
-
|
99
|
-
]
|
100
|
-
|
101
|
-
};
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
WavEncoder.encode(audioData).then((buffer) => {
|
106
|
-
|
107
|
-
let url = 'https://api.webempath.net/v2/analyzeWav';
|
108
|
-
|
109
|
-
let formData = {
|
110
|
-
|
111
|
-
'apikey' : 'uC1rNGnGOFNiY4t8PC_HZYH3a6dpK_HB7Z1ABux7o7o',
|
112
|
-
|
113
|
-
'wav': Buffer.from(buffer),
|
114
|
-
|
115
|
-
'timeout': '100000' //milliseconds
|
116
|
-
|
117
|
-
};
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
// Empath API へ投げる
|
122
|
-
|
123
|
-
webclient.post({url:url, formData:formData}, function (error, response, body){
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
// 録音終了を検知して処理を開始
|
128
|
-
|
129
|
-
io.on('connection', function(socket) {
|
130
|
-
|
131
|
-
socket.emit('respons', body );
|
132
|
-
|
133
|
-
console.log('API Respons OK');
|
134
|
-
|
135
|
-
});
|
136
|
-
|
137
|
-
});
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
});
|
144
|
-
|
145
|
-
}
|
146
|
-
|
147
69
|
|
148
70
|
|
149
71
|
// 読み込みファイル定義
|