playTone method

Future<bool> playTone({
  1. required String digits,
  2. int? durationMs,
  3. double? samplingRate,
  4. double? volume,
})

Plays the DTMF Tones Associated with the digits. Each tone is played for the duration durationMs in milliseconds Returns true if tone played successfully

Implementation

Future<bool> playTone(
    {required String digits,
    int? durationMs,
    double? samplingRate,
    double? volume}) {
  dynamic audioContext = js.context.callMethod('AudioContext',
      ['new (window.AudioContext || window.webkitAudioContext)()']);

  for (var i in digits.split('')) {
    var tone = Tone(
        context: audioContext,
        frequency1: allFrequencies[i]![0],
        frequency2: allFrequencies[i]![1]);
    if (tone.status == 0) {
      tone.start();
      tone.stop();
      return Future.value(true);
    }
  }

  return Future.value(false);
}