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 ;
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 >
5776let 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 = `
87109import struct
88110import numpy as np
89111import scipy
90- from js import wavBytes
112+ from js import wav_bytes
113+
114+ wav_bytes = bytes(wav_bytes.to_py())
91115
92116def 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
105129def 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