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

Ionic 4 - Browser audio input doesn't work #95

Open
Merwan1010 opened this issue Aug 17, 2019 · 7 comments
Open

Ionic 4 - Browser audio input doesn't work #95

Merwan1010 opened this issue Aug 17, 2019 · 7 comments
Labels
enhancement This is a feature that should be implemented. help wanted The great thing about open-source is that everyone can contribute!

Comments

@Merwan1010
Copy link

Merwan1010 commented Aug 17, 2019

Hi,

I have a problem really similar to this post : #85

The plugin is working well on my android device but when i do ionic cordova run browser and load the tab, i have this error in the console :
Screen Shot 2019-08-17 at 17 47 44

Here is the code in the ts file of the tab4 component :

declare let audioinput: any;

import { Component, OnInit } from '@angular/core';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { File } from '@ionic-native/file/ngx';

@Component({
  selector: 'app-tab4',
  templateUrl: './tab4.page.html',
  styleUrls: ['./tab4.page.scss'],
})
export class Tab4Page implements OnInit {

  BUFFER_SIZE: number = 16384;

  constructor(private platform: Platform, private splashScreen: SplashScreen, private statusBar: StatusBar, private file: File) {
    platform.ready().then((source) => {
      console.log("platform source " + source);
    });
  }

  ngOnInit() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();

      window.addEventListener('audioinput', (event: any) => {
        //alert(JSON.stringify(event.data));
        alert( "Audio data received: " + event.data.length + " samples" );
      }, false);

      audioinput.checkMicrophonePermission((hasPermission) => {
        if (hasPermission) {
          console.log("We already have permission to record.");
          this.startCapture();
        }
        else {
          // Ask the user for permission to access the microphone
          audioinput.getMicrophonePermission((hasPermission, message) => {
            if (hasPermission) {
              console.log("User granted us permission to record.");
              this.startCapture();
            } else {
              console.warn("User denied permission to record.");
            }
          });
        }
      });
    });
  }

  public startCapture() {
    audioinput.start({
      bufferSize: this.BUFFER_SIZE,
      streamToWebAudio: false,
      normalize: true,
      channels: audioinput.CHANNELS.MONO,
      sampleRate: audioinput.SAMPLERATE.CD_AUDIO_44100Hz,
    });
  }

}

Do you know what cause the error ?

Thank you

@edimuj
Copy link
Owner

edimuj commented Sep 20, 2019

It doesn't seem to work either on an emulator or the browser. The point of the plugin is mainly to enable audio capture on iOS devices and older Android devices that haven't support for getUserMedia as most modern desktop browsers do.

@Merwan1010
Copy link
Author

Actually its working fine on ios emulator for me, on android emulator i have a mute microphone but maybe this is just some settings for the emulator.
Thanks for your answer, i will use a different approach for browser.

@numerized
Copy link

Would be so awesome to make it work on the browser.
It'll be so cool to have one codebase for all really.

@numerized
Copy link

@edimuj maybe you'd accept a little donation to make it work?

@edimuj
Copy link
Owner

edimuj commented Dec 18, 2019

@numerized well time is more of the issue, but donations are of course always happily accepted 🎁😊

Anyway, I will try to look into this in the coming weeks. Christmas is always a good time to do some housekeeping.

@edimuj edimuj added enhancement This is a feature that should be implemented. help wanted The great thing about open-source is that everyone can contribute! labels Dec 18, 2019
@numerized
Copy link

Cool! :)

@nth-chile
Copy link

It tries to do string replacement on fileURL, which is a problem if fileURL is null

// AudioInputCaptureProxy.js

96   fileUrl = opts[5] || fileUrl;
97   // the URL must be converted to a cdvfile:... URL to ensure it's readable from the outside
98   fileUrl = fileUrl.replace("filesystem:file:///", "cdvfile://localhost/");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is a feature that should be implemented. help wanted The great thing about open-source is that everyone can contribute!
Projects
None yet
Development

No branches or pull requests

4 participants