Record audio input with Microphone

I would like the ability to access a device’s microphone and record and play back short audio clips (<10 seconds).

I’m a speech therapist and would like to add this feature to my game so my students can play back clips of what they said and compare.

Evidently there used to be a microphone extension but it isn’t available anymore.

2 Likes

Thanks! I actually didn’t realize Gdevelop is built on Javascript so that’s good to know

Considering the importance of audio feedback in speech therapy, how can I incorporate microphone access and the ability to record/playback short audio clips (less than 10 seconds) into my educational game for students, especially given the unavailability of the previous microphone extension?

Hey wadu,
Someone had replied with a suggestion to look into some code in Javascript that allows this. I have not had the time to do so yet, but I think that’s a good place to start!

Can you be more specific about what you want?

How would you apply it in more detail?

I just need the client to hear their own speech played back to them. For example, there is an icon of a radio on the screen and I want to record the client saying the word ‘radio’. I’d like a button that, when touched, would use the mic to record short audio clips, which would be played via a different button. Once the record button is pressed again, the previous recording should be overwritten–I don’t need to save recordings long-term.

Okay, ill see what i can do, check back later! :slight_smile:

1 Like

Nope i give up…

I wasted an entire morning on this and nothing…

I can get the microphone to work, thats easy, i can get it to record audio into a specific folder and audio file, i can get it to re write the file…

But heres the issue, GDevelop dosent play overwritten files once the game launches.

I also cant use an expression to play Audio files, so i cant even make temporary different files and then play them based on their name…

I can probably do it with more scripting, but honestly i have my own work to do…

I gave it my best, but some one smarter than me needs to make this stuff work.

The sad part is, this stuff is simple to get going, the only issue im having is that it would take the rest of the day to work out the system with java by going into the source code to see how the audio manager handles playing stuff, so that i can then play temporary sounds…

If someone knows the engine, they can make this stuff in minutes…

Thanks for trying!
I have ideas for other games where recording isn’t a necessity so I’ve just been working on those in the meantime.

1 Like

I was thinking about trying something like this today, I plan to spend some time to see if I can make it work

Looking at the code, it seems like the play audio event uses the HowlerSoundManager to load an audio resource from gdjs.ResourceLoader, which appears to link back to the project Resources manager. As far as I can tell from the code, the only way to add a resource at runtime is to do a hot reload (add a ResourceData with ResourceKind = “audio” using the object returned by gdjs.createProjectData() and then call runtimegame.setProjectData() to reload). Doesn’t seem that complicated from a code perspective, but haven’t had a chance to implement and test.

I was able to get this working. I need to clean up my code, but the gist is:

  1. Get mic MediaStream as a blob
  2. Convert blob to base64 using readAsDataURL()
  3. Add a resource to the project data using the base64 string as the file, and then do hot reload
  4. Play the sound back using the sound manager playSound() method

EDIT: I’m not allowed to make another post, so editing this one. I’ve implemented a simple recording/playback app which anyone else can try at Audio record playback | Play on gd.games

I tried on my PC and iPhone with chrome/safari and it seems to work for me.

If anyone is interested I can share the code

EDIT2: still need someone else to reply before I can make a new post. Submitted a community extension but it hasn’t been merged yet. Should be available at New extension: AudioVisualizer · Issue #1408 · GDevelopApp/GDevelop-extensions · GitHub for now

2 Likes