Hi, I’m trying to create a KMP module for audio pr...
# javascript
o
Hi, I’m trying to create a KMP module for audio processing and want to split the processor code into a separate JS file, similar to this example: // script.js
await audioContext.audioWorklet.addModule("hiss-generator.js");
// hiss-generator.js
registerProcessor("hiss-generator", HissGeneratorProcessor);
I tried to creating the processor in another module with:
Copy code
// processor/build.gradle.kts
commonWebpackConfig {
    outputFileName = "audio-processor.js"
}
But when I add it as a dependency to the app,
audio-processor.js
isn’t included in the
dist
output. What am I missing?
t
Do you use Kotlin Warappers?
o
yep, currently I do it like in this example:
Copy code
context.audioWorklet.addModule(blobUrl)
where the blobUrl is raw JS string, but I’d prefer to write it in Kotlin.
t
We already support
Worker
creation without separate subproject creation - example.
AFAIK Webpack doesn't support worklet modules without loaders 😞
We can support worklet modules, but they will work only with Vite bundler (recommended).
Could you please create issue? I will add example of worklet creation
o
sure, Thanks! So, what do you think is the best approach right now? Do you have any examples on how to set it up?
t
It will be something like this:
Copy code
// MyAydioWorkletModule.kt
val MyAydioWorkletModule = AudioWorkletModule {
    // this - AudioWorkletGlobalScope
}

// App.kt
audioContext.audioWorklet.addModule(MyAydioWorkletModule)
All additional magic Vite and Seskar will do 😉
o
Too good to be true 😅. BTW the issue has been created.
thank you color 1
t
Please add links on JS examples in issue
👌 1
o
I saw AudioWorkletModule was merged and released — is it ready to go?
t
I added MDN example here. Compiler plugin support - next (final) step. Hope it will be ready this week 😉
kodee happy 1
In any case I will write in this thread when it will be ready.
Example in Seskar works!
🎉 1
Plugin will be released later
Plugin released.