-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.html
77 lines (65 loc) · 2.21 KB
/
test.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- including ECharts file -->
<script src="./node_modules/echarts/dist/echarts.min.js"></script>
<title>Test page for wasmsox</title>
<base href=".">
</head>
<body>
<h1>Test page for wasmsox</h1>
<h2>Enter sox command here:</h2>
<p><b>Hint</b> there is an input file saved to the file system called input.wav </p>
<input
id="sox_command"
type="text"
size="100"
value="sox --i input.wav">
<p>
<button onclick="runCommand()">run command</button>
</p>
<h2>If a file named <code>output.wav</code> is generated you can play it here:</h2>
<audio id="audio" controls autoplay></audio>
<h2>sox output</h2>
<b>TODO: capture output</b>
<script src="./wasmsox.js"></script>
<script>
let inited = false;
let api = undefined;
async function loadAudio(src) {
// Load audio
const audio_ab = await fetch(src).then(resp => resp.arrayBuffer());
return audio_ab;
}
function runCommand(){
console.log(api);
// use exposed api function performedAssp:
try{
let return_code = api.performSox(document.getElementById('sox_command').value);
} catch(e){
console.error(e);
}
console.log(return_code);
if(return_code === 0){
// add file to audio element 4 playback
let out_file = FS.readFile("output.wav");
const blob = new Blob([out_file], { type: "audio/wav" });
document.getElementById('audio').src = window.URL.createObjectURL(blob);;
FS.unlink("output.wav");
}
}
Module.onRuntimeInitialized = async _ => {
api = {
performSox: Module.cwrap('performSox', 'number', ['string'])
};
// load audio file as arrayBuffer using fetch:
const audioFileBuffer = await loadAudio('./resources/msajc003.wav');
// save arraybufferview to FS -> so fopen() in wasmassp can read file
FS.writeFile('input.wav', new Uint8Array(audioFileBuffer));
inited = true;
}
</script>
</body>
</html>