The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+2 votes

I would like to create a voice changer app in godot.

I created a minimal recorder in C++ that records mic input into a .wav file. I connected the recorder with GDScript via GDNative interface.

The wav file is output to "user://rec.wav". The file is generated correctly - I'm able to play it in other audio players and also in godot(from res://).
However, when I try to load the file with load("user://rec.wav") I get the following error No loader found for resource: user://rec.wav

I'm using godot 3.0.1 that I've build from sources.

What is correct way of loading wav/pcm that is created during runtime?

I'm new to Godot, so it's possible that I've missed something obvious...but I really first searched the docs and qa before asking here.

in Engine by (38 points)

can you access file without problem? e.g."user://rec.wav") returns true value?

Yes, file_exists returns true

2 Answers

+1 vote
Best answer

It is possible to load ogg and wav files during runtime by setting data format``stereo properties of appropriate audiostream object demo for stereo wav:

var file =
var stream
if file.file_exists(audio_file):, file.READ)
  var buffer = file.get_buffer(file.get_len())
  stream =
  stream.format = AudioStreamSample.FORMAT_16_BITS = buffer
  stream.stereo = true

old answer:
It looks like this is not possible for now.I've created an issue at official repository, if it became resolved I'll update answer.

by (1,024 points)
edited by

I still get the same error.
However, thank you for your answers. So you think that this is the right way and it should be possible to load from user://...

Sorry, I misinformed you - check my updated answer.

Ok, thank you for your help.
I was hoping I could do most of the stuff from GDScript/GDNative, but I'll anyway have to create a C++ module for my other required features.

I think I'll create a custom AudioStream/AudioStreamPlayback that will directly supply mic input to the AudioStreamPlayer. The stream could already save/load audio data as raw pcm.

I've asked another question here - I would like to get the processed output once audio effects have been applied. Could you please look at that one too? I don't think it will be possible from GDScript, but I at least would like to find strategies how to do it from C++ module.

I've started learning Godot only few weeks ago so unfortunately I'm not familiar enough with engine c++ implementation to help with yours outher question.

after all it is possible to load audio files at runtime using gdscript. check updated answer

Perfect, now it works. I just had to strip the wav header, and then it worked.
Thanks again

Hello, i´m struggling with your same problem, your code works great but i noticed that it only works with some kind of wav files (the ones with a bit rate of 1411 kbps). Other files (higher bit rate) are executed as white sound.
Do you know a way to set bit rate in the audiostreamsample?

I am able to play the wav by doing this.
However, the result is very distorted and noisy (pitch and duration are correct), whereas the file that is imported using the editor is clean and clear.
The settings are the same, because I compared what they should be from .import file.
Any idea how I can still improve this?

+1 vote
by (64 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.