Skip to content

Commit 9b4f2d0

Browse files
Update WAV processing and add GitHub link
1 parent 09c8825 commit 9b4f2d0

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

index.html

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
width: 100%;
2727
max-width: 600px;
2828
text-align: center;
29-
transition: background 0.3s, color 0.3s;
3029
font-size: 1.2rem;
30+
transition: background 0.3s, color 0.3s;
31+
cursor: pointer;
3132
}
3233
.drop-area.dragover {
3334
background: #ff6f61;
@@ -44,6 +45,20 @@
4445
overflow-x: auto;
4546
min-height: 200px;
4647
}
48+
.github-link {
49+
margin-top: 1.5rem;
50+
font-size: 1rem;
51+
color: #ff6f61;
52+
text-decoration: none;
53+
border: 1px solid #ff6f61;
54+
padding: 0.5rem 1rem;
55+
border-radius: 8px;
56+
transition: background 0.3s, color 0.3s;
57+
}
58+
.github-link:hover {
59+
background: #ff6f61;
60+
color: #1e1e2f;
61+
}
4762
</style>
4863
</head>
4964
<body>
@@ -53,6 +68,10 @@ <h1>MakeCode Arcade WAV Converter</h1>
5368
</div>
5469
<pre id="output">Output will appear here...</pre>
5570

71+
<a href="https://github.com/HomeAssistantTycoon/Audio-to-MakeCode-Arcade" target="_blank" class="github-link">
72+
Support this project on GitHub ⭐
73+
</a>
74+
5675
<script>
5776
let pyodideReadyPromise = loadPyodide({indexURL: "https://cdn.jsdelivr.net/pyodide/v0.26.3/full/"});
5877

@@ -77,17 +96,22 @@ <h1>MakeCode Arcade WAV Converter</h1>
7796
output.textContent = "Please provide a WAV file.";
7897
return;
7998
}
99+
80100
output.textContent = "Loading Python runtime...";
81101
const pyodide = await pyodideReadyPromise;
82102

83103
const arrayBuffer = await file.arrayBuffer();
84104
const wavBytes = new Uint8Array(arrayBuffer);
85105

106+
pyodide.globals.set("wav_bytes", wavBytes);
107+
86108
const pyCode = `
87109
import struct
88110
import numpy as np
89111
import scipy
90-
from js import wavBytes
112+
from js import wav_bytes
113+
114+
wav_bytes = bytes(wav_bytes.to_py())
91115
92116
def constrain(value, min_value, max_value):
93117
return min(max(value, min_value), max_value)
@@ -104,7 +128,7 @@ <h1>MakeCode Arcade WAV Converter</h1>
104128
105129
def audio_to_makecode_arcade(wav_bytes, period=25, gain=2.5):
106130
from io import BytesIO
107-
sample_rate, data = scipy.io.wavfile.read(BytesIO(wav_bytes.to_py()))
131+
sample_rate, data = scipy.io.wavfile.read(BytesIO(wav_bytes))
108132
109133
if len(data.shape) > 1 and data.shape[1] > 1:
110134
data = data[:, 0]
@@ -150,7 +174,7 @@ <h1>MakeCode Arcade WAV Converter</h1>
150174
)
151175
return code
152176
153-
audio_to_makecode_arcade(wavBytes)
177+
audio_to_makecode_arcade(wav_bytes)
154178
`;
155179

156180
output.textContent = "Converting...";

0 commit comments

Comments
 (0)