Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova/Javascript audio recording

I've been working for a little bit on a new app using Cordova, VueJs and Onsen UI (for VueJs), and now I want to implement, using the microphone in an Android or iOS device, recording some audio and sending it to the Google Speech to Text API.

I get how the data would be sent to the API, but my main issue is how I would record the data from a mobile device and use it (temporarily, not saved to the device itself, unless there is no network connection, then the data should be saved and the request to the API should be queued until there is a stable network connection).

There are a couple of things I need to implement: - Selectable bitrate - Detecting how much space there is left on the device to calculate maximum recording length (nice to have) - Longer recording time (as long as there is space basically, or limiting it if there is no (simple) way of cutting it into multiple pieces) - Able to implement custom UI

I've looked up several ways to do this, but most tutorials/guides/documentations are outdated, feature deprecated functions/methods or have a set UI.

I've tried most recommended Cordova plugins, the only one that did work had a set UI, which is a no go for me, a custom UI is required for the app I'm working on. Also on the list of things I've tried is getUserMedia(), directly on my iPhone using the Safari developer tools, which returned undefined.

Please do correct me if I'm wrong and missed some amazing native functionality or some npm package/Cordova plugin.

Any suggestions or links are welcome!

Edit: To sum it up, I am looking for the mainstream way (for both platforms, preferably using the same code) to record audio, temporarily store it if required and do things with it (like sending it to the API).

Edit 2: The client just gave some new requests, which changed the scope of the app quite a bit. One of the changes requested (and for the client, this is the most important feature) is that I save the audiofile recorded by the user, so it can be played back at any moment. Syncing between devices won't be applied. The question is still mostly the same, but I do need to save the recorded audio.

like image 797
Christian Kaal Avatar asked Nov 07 '22 22:11

Christian Kaal


1 Answers

For a very simple usage have you tried the standard plugin ? I know that you have said that you have already tested some plugins but I've used in some old pet project and it worked, so maybe it's a problem invoking the plugin:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-media/index.html#mediastartrecord

This is very simple, if you need more control I'm afraid that you have to create a custom plugin using native code. We have done something like that to access Android equalizer and other features.

like image 111
wezzy Avatar answered Nov 10 '22 00:11

wezzy