Introducing Flutter Audio

Written by iurii-gurzhii | Published 2020/03/01
Tech Story Tags: flutter | flutter-for-mobile-app | flutter-audio | application | android | android-app-development | android-development | open-source | web-monetization

TLDR Evrone created Flutter Audio for Medcorder, a mobile app that records and decode conversations with doctors and other medical staff. The plug-in was originally created for Google's Speech Recognition services. The interface is designed with ease-of-use in mind and doesn’t offer fine-grained control over the recording settings. The project has been released as an open source contribution by Evrone. Evrone is pleased to see that there have been quite a few forks of the project on GitHub aimed at different applications.via the TL;DR App

We’re big fans here at Evrone of Google’s Flutter SDK for building Android and iOS apps, but when we were building Medcorder, we ran into a problem: there wasn’t a way to record speech using the Google-provided APIs. The client who we were developing Medcorder for came up with the idea of the development of the audio recording plugin as an open source contribution. So, we built an audio recording plug-in for the project!
Medcorder is a mobile application that records and helps decode conversations with doctors and other medical staff. The information that’s captured can then be passed on to relatives and other specialists so that they don’t miss any key details from a consultation.
There are three parts to Flutter Audio:
The interface, which like Flutter itself, is pure DartA native component written in Objective-C does the heavy lifting on iOSMeanwhile, on Android, we developed an equivalent in Java
After the plug-in was created, our client offered us the opportunity to release it as open source, which we were very happy to do.
It’s worth noting that Flutter Audio was originally created — and is optimised — for Google's Speech Recognition services, and the interface is designed with ease-of-use in mind and doesn’t offer fine-grained control over the recording settings. We’re quite happy with the “do one thing and do it well” approach that we’ve taken, and so we’re not accepting pull requests that seek to alter the audio profiles or expose recording parameters. We’re very pleased to see that there have been quite a few forks of the project on GitHub aimed at different applications, and we’ll continue to watch them with interest.
We don’t know what Google’s plans for official audio recording capabilities in Flutter might be, but we’re delighted by the engagement Flutter Audio’s had from the community so far.
Using Flutter Audio is straightforward. First, you’ll need an instance of  MedcorderAudio:
MedcorderAudio audioModule = new MedcorderAudio();
Then, you need to make sure that you can actually record audio on your device and apply the audio settings required for speech recording. We’d typically do this in our initState method with something along the lines of the following:
final String result = await audioModule.checkMicrophonePermissions();
if (result == 'OK') {
  await audioModule.setAudioSettings();
  setState(() {
    canRecord = true;
  });
}
Once you know you can record, use the audioModule to start recording in an event handler invoked when a user pushes a button:
try {
  final String result = await audioModule.startRecord(filename);
  setState(() {
    isRecord = true;
  });
  print('startRecord: ' + result);
} catch (e) {
  print('startRecord: failed');
}
…and stopping recording again is just as straightforward:
final String result = await audioModule.stopRecord();
print('stopRecord: ' + result);
setState(() {
  isRecord = false;
});
To help you get started, we’ve put all of this into an example app for iOS and Android. See in particular the main.dart that actually interacts with the plug-in.
In the event that you encounter a bug, please do open an issue and we’ll try to squash it as soon as we can.
We hope you find Flutter Audio (and its variants) useful, and we’re excited to see what people do with it!


Written by iurii-gurzhii | Evrone.com
Published by HackerNoon on 2020/03/01