Channel Streamer Erorr Enhancement of error handling
parent
166ec17fcf
commit
d8138f6110
|
@ -8,7 +8,9 @@ import fs from 'fs'
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
|
|
||||||
|
|
||||||
|
alias: {
|
||||||
|
'@': path.resolve(__dirname, ''),
|
||||||
|
},
|
||||||
|
|
||||||
devServer: {
|
devServer: {
|
||||||
|
|
||||||
|
|
|
@ -18,53 +18,67 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async startMicrophone() {
|
async startMicrophone() {
|
||||||
|
try {
|
||||||
this.audioContext = new window.AudioContext ();
|
this.initializeAudioContext();
|
||||||
|
await this.requestMicrophoneAccess();
|
||||||
// Request access to the microphone
|
await this.setupAudioProcessing();
|
||||||
this.microphoneStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
} catch (error) {
|
||||||
|
console.error('Error starting microphone:', error.message);
|
||||||
// Check if the microphone stream is available
|
this.errorMessage = error.message;
|
||||||
if (!this.microphoneStream) {
|
}
|
||||||
console.error("Microphone stream is not available.");
|
|
||||||
this.errorMessage = "Microphone stream is not available.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that the microphoneStream is a MediaStream object
|
|
||||||
if (!(this.microphoneStream instanceof MediaStream)) {
|
|
||||||
console.error("Invalid microphone stream.");
|
|
||||||
this.errorMessage = "Invalid microphone stream.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a MediaStreamAudioSourceNode from the microphone stream
|
|
||||||
const microphoneSource = this.audioContext.createMediaStreamSource(this.microphoneStream);
|
|
||||||
await this.audioContext.audioWorklet.addModule('@/plugins/octave.js');
|
|
||||||
this.audioProcessorNode = new AudioWorkletNode(this.audioContext, 'octave');
|
|
||||||
microphoneSource.connect(this.audioProcessorNode);
|
|
||||||
this.audioProcessorNode.connect(this.audioContext.destination);
|
|
||||||
// Try to add the Audio Worklet module
|
|
||||||
|
|
||||||
},
|
},
|
||||||
stopMicrophone() {
|
stopMicrophone() {
|
||||||
|
this.cleanup();
|
||||||
|
},
|
||||||
|
initializeAudioContext() {
|
||||||
|
this.audioContext = new window.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() {
|
||||||
|
try {
|
||||||
|
const microphoneSource = this.audioContext.createMediaStreamSource(this.microphoneStream);
|
||||||
|
await this.audioContext.audioWorklet.addModule('@/plugins/octave.js');
|
||||||
|
|
||||||
|
//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.');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cleanup() {
|
||||||
if (this.audioContext) {
|
if (this.audioContext) {
|
||||||
// Disconnect and close the AudioWorkletNode
|
|
||||||
if (this.audioProcessorNode) {
|
if (this.audioProcessorNode) {
|
||||||
this.audioProcessorNode.disconnect();
|
this.audioProcessorNode.disconnect();
|
||||||
this.audioProcessorNode.port.postMessage({ command: 'stop' });
|
this.audioProcessorNode.port.postMessage({ command: 'stop' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the AudioContext
|
|
||||||
this.audioContext.close();
|
this.audioContext.close();
|
||||||
|
this.resetVariables();
|
||||||
// Reset variables
|
|
||||||
this.audioContext = null;
|
|
||||||
this.microphoneStream = null;
|
|
||||||
this.audioProcessorNode = null;
|
|
||||||
this.errorMessage = null;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
resetVariables() {
|
||||||
|
this.audioContext = null;
|
||||||
|
this.microphoneStream = null;
|
||||||
|
this.audioProcessorNode = null;
|
||||||
|
this.errorMessage = null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
this.cleanup();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
console.log('Octave module loaded successfully!');
|
||||||
new AudioWorkletProcessor ()
|
new AudioWorkletProcessor ()
|
||||||
|
|
||||||
class OctaveBandProcessor extends AudioWorkletProcessor {
|
class OctaveBandProcessor extends AudioWorkletProcessor {
|
||||||
|
|
Loading…
Reference in New Issue