SimformSolutionsPvtLtd / audio_waveforms

Use this plugin to generate waveforms while recording audio in any file formats supported by given encoders or from audio files. We can use gestures to scroll through the waveforms or seek to any position while playing audio and also style waveforms
https://pub.dev/packages/audio_waveforms
MIT License
275 stars 141 forks source link

AudioWaveforms with RecorderController does not show any waves #247

Open vongrad opened 12 months ago

vongrad commented 12 months ago

Describe the bug I cloned audio_waveforms GitHub repo, opened up the example project and ran it on iPhone 14 Pro (iOS 16.4) emulator, however the waves are shown when recording the audio. (I have not modified any of your code)

To Reproduce Steps to reproduce the behavior:

  1. Clone audio_waveforms repo
  2. Open up the example project
  3. Run it on iOS emulator (16.4)
  4. Start recording the sound
  5. No visual waves are shown, just dots with [x*t, 0]

Expected behavior The waves should react to recorded audio.

Smartphone (please complete the following information):

hossam-96 commented 8 months ago

https://github.com/SimformSolutionsPvtLtd/audio_waveforms/assets/26495484/6fb240cc-66a8-4e12-916d-6d275d60bb76

I have the same issue with my phone Phone Model: Realme 5 pro Android Version: 10

It works fine with the rest of emulators and devices ( Android & iOS )

Priyanshu85 commented 7 months ago

I got the same issue, did you get any solutions?

Ujas-Majithiya commented 6 months ago

@vongrad Can please use the new 1.0.5 version and #242 might have had fixed this.

jt274 commented 4 months ago

I am also experiencing this on a physical device, iOS 17.4.1. Latest version 1.0.5.

Heropowwa commented 4 months ago

I've got the same problem using the new version on android

Ujas-Majithiya commented 4 months ago

I tested on an iPhone 14 simulator with IOS 17.2 recording waves are generating just fine for me. Did you get any exceptions or logs while recording? If you can share it then I would help us find the issue.

Heropowwa commented 4 months ago

This is the code of the widget that i use to record:

import 'package:audio_waveforms/audio_waveforms.dart';
import 'package:chat/Controller/AudioController.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class RecordAudioMessage extends StatefulWidget {
  const RecordAudioMessage({super.key});

  @override
  State<RecordAudioMessage> createState() => _RecordAudioMessageState();
}

class _RecordAudioMessageState extends State<RecordAudioMessage> {
  AudioController audioController = Get.put(AudioController());

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AudioWaveforms(
      size: Size(MediaQuery.of(context).size.width * 0.5, 25),
      recorderController: audioController.recorderController,
      enableGesture: true,
      waveStyle: const WaveStyle(
        extendWaveform: true,
        showMiddleLine: false,
      ),
    );
  }
}

This is the audio controller:

import 'dart:io';
import 'package:audio_waveforms/audio_waveforms.dart';
import 'package:chat/Controller/ProfileController.dart';
import 'package:get/get.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';

class AudioController extends GetxController {
  RxString recordFilePath = "".obs;
  RxString audioUrl = "".obs;
  RxBool isRecording = false.obs;
  RxBool isPlayingMsg = false.obs;
  ProfileController profileController = Get.put(ProfileController());
  PlayerController playerController = PlayerController();
  late final RecorderController recorderController;
  late String? path;
  bool isInitialised = false;

  Future<String> getFilePath() async {
    Directory storageDirectory = await getApplicationDocumentsDirectory();
    String sdPath = "${storageDirectory.path}/record";
    var d = Directory(sdPath);
    if (!d.existsSync()) {
      d.createSync(recursive: true);
    }
    return "$sdPath/audio.mpeg4";
  }

  Future<bool> checkPermission() async {
    if (!await Permission.microphone.isGranted) {
      PermissionStatus status = await Permission.microphone.request();
      if (status != PermissionStatus.granted) {
        return false;
      }
    }
    return true;
  }

  void initialiseController() {
    if (isInitialised) {
    } else {
      recorderController = RecorderController()
        ..androidEncoder = AndroidEncoder.aac
        ..androidOutputFormat = AndroidOutputFormat.mpeg4
        ..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC
        ..sampleRate = 44100
        ..bitRate = 48000;
      isInitialised = true;
    }
  }

  void startRecording() async {
    initialiseController();
    bool hasPermission = await checkPermission();
    if (hasPermission) {
      isRecording.value = true;
      recordFilePath.value = await getFilePath();
      await recorderController.record(path: recordFilePath.value);
    } else {
      //Toast error
    }
  }

  void stopRecording() async {
    final path = await recorderController.stop();
    isRecording.value = false;
    print(path);
  }
}

The device i use for testing is a Redmi Note 12 with Android 14. I haven't got any particular log while recording.

Ujas-Majithiya commented 4 months ago

The bitrate value of 48k falls outside of the supported range of mpeg4 audio format on Android. Can you please try a higher bitrate value?

Heropowwa commented 4 months ago

I tried this:

 void initialiseController() {
    if (isInitialised) {
    } else {
      recorderController = RecorderController()
        ..androidEncoder = AndroidEncoder.aac
        ..androidOutputFormat = AndroidOutputFormat.mpeg4
        ..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC
        ..sampleRate = 44100
        ..bitRate = 128000;
      isInitialised = true;
    }
  }

But it still doesn't show waves while recording.

Screenshot_2024-05-07-13-43-41-466_com example chat

Heropowwa commented 4 months ago
 void initialiseController() {
    if (isInitialised) {
    } else {
      recorderController = RecorderController()
        ..androidEncoder = AndroidEncoder.opus
        ..androidOutputFormat = AndroidOutputFormat.ogg
        ..iosEncoder = IosEncoder.kAudioFormatOpus
        ..sampleRate = 44100;
      isInitialised = true;
    }
  }

I've changed to these settings and now it works, I've did some other tests and the problem seems to be in the AAC Encoder on Android.