Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioWaveforms with RecorderController does not show any waves #247

Open
vongrad opened this issue Sep 14, 2023 · 10 comments
Open

AudioWaveforms with RecorderController does not show any waves #247

vongrad opened this issue Sep 14, 2023 · 10 comments
Labels
in triage The issue is being triaged waiting-for-response Waiting for someone to respond.

Comments

@vongrad
Copy link

vongrad commented Sep 14, 2023

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):

  • Device: iPhone 14 Pro (emulator)
  • OS: IOS 16.4
@hossam-96
Copy link

hossam-96 commented Dec 18, 2023

Record_2023-12-18-16-15-20_5b79e241dbc93926bd2a3da8938c46b1.mp4

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
Copy link

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

@Ujas-Majithiya
Copy link
Collaborator

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

@Ujas-Majithiya Ujas-Majithiya added the waiting-for-response Waiting for someone to respond. label Mar 16, 2024
@jt274
Copy link

jt274 commented Apr 18, 2024

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

@Heropowwa
Copy link

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

@Ujas-Majithiya
Copy link
Collaborator

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.

@Ujas-Majithiya Ujas-Majithiya added the in triage The issue is being triaged label May 5, 2024
@Heropowwa
Copy link

Heropowwa commented May 6, 2024

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
Copy link
Collaborator

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
Copy link

Heropowwa commented May 7, 2024

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
Copy link

Heropowwa commented May 8, 2024

 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in triage The issue is being triaged waiting-for-response Waiting for someone to respond.
Projects
None yet
Development

No branches or pull requests

6 participants