Nuxt (.vue) with Audio Web API

76 views Asked by At

im trying to . add a model using the following method :

    async startMicrophone() {
      try {
        this.initializeAudioContext();
        await this.requestMicrophoneAccess();
        await this.setupAudioProcessing();
      } catch (error) {
        console.error('Error starting microphone:', error.message);
        this.errorMessage = error.message;
      }
    },
  initializeAudioContext() {
      // this.audioContext = new window.AudioContext();
      this.audioContext = new AudioContext();
    },
    async requestMicrophoneAccess() {
      try {
        this.microphoneStream = await navigator.mediaDevices.getUserMedia({ audio: true });
      } catch (error) {
        console.error('Error accessing microphone:', error.message);
        this.errorMessage = 'Microphone access denied. Please grant permission in your browser settings.';
        throw new Error('Microphone access denied.');
      }

      if (!this.microphoneStream || !(this.microphoneStream instanceof MediaStream)) {
        throw new Error('Microphone stream is not available.');
      }
    },
    async setupAudioProcessing() {
      const microphoneSource = this.audioContext.createMediaStreamSource(this.microphoneStream);
      
  try {
    await this.audioContext.audioWorklet.addModule("octave.js");
   
    await this.audioContext.resume();
    // console.log('Octave module loaded successfully!');
    
    console.log('Octave module loaded successfully!');

    this.audioProcessorNode = new AudioWorkletNode(this.audioContext, 'octave');
    microphoneSource.connect(this.audioProcessorNode);
    //this.audioProcessorNode.connect(this.audioContext.destination);
  } catch (error) {
    console.error('Error setting up audio processing:', error.message);
    this.errorMessage = 'Error setting up audio processing. Please check your microphone and try again.';
    throw new Error('Audio processing setup failed.');
  }
  },

and keep getting an error calling the .js model even if the path is right as the .js is in the same folder :

ChannelStreamer.vue:65 
 Error setting up audio processing: The user aborted a request.
setupAudioProcessing    @   ChannelStreamer.vue:65
await in setupAudioProcessing (async)       
startMicrophone @   ChannelStreamer.vue:24
await in startMicrophone (async)        
_createElementVNode.onClick._cache.<computed>._cache.<computed> @   ChannelStreamer.vue:3
callWithErrorHandling   @   chunk-PII4CCGD.js:1739
callWithAsyncErrorHandling  @   chunk-PII4CCGD.js:1747
invoker @   chunk-PII4CCGD.js:9975
ChannelStreamer.vue:26 
 Error starting microphone: Audio processing setup failed.
startMicrophone @   ChannelStreamer.vue:26
await in startMicrophone (async)        
_createElementVNode.onClick._cache.<computed>._cache.<computed> @   ChannelStreamer.vue:3
callWithErrorHandling   @   chunk-PII4CCGD.js:1739
callWithAsyncErrorHandling  @   chunk-PII4CCGD.js:1747
invoker

could you please give a Hint why the error is happening ?i defined the AudioWorkletProcessor as in the documentation :

class MyAudioProcessor extends AudioWorkletProcessor {
  constructor() {
    super();
  }

  process(inputList, outputList, parameters) {
    // Using the inputs (or not, as needed),
    // write the output into each of the outputs
    // …
    return true;
  }
}

registerProcessor("my-audio-processor", MyAudioProcessor);

many thanks
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

0

There are 0 answers