vue-advanced-chat icon indicating copy to clipboard operation
vue-advanced-chat copied to clipboard

Voice in voice note got heavy pitch as compare to original voice

Open Furqan2 opened this issue 2 years ago • 11 comments

Describe the bug

When we send a recorded voice note in the chat it got heavy pitch and voice is clearly diffrent from original voice..

Furqan2 avatar Sep 14 '22 13:09 Furqan2

Indeed the voice sounds a bit strange... I will check that

antoine92190 avatar Sep 14 '22 13:09 antoine92190

I cannot reproduce anymore... Do you still have the issue on your side?

antoine92190 avatar Sep 14 '22 16:09 antoine92190

Yes , you can test in the demo also

https://antoine92190.github.io/vue-advanced-chat/

Furqan2 avatar Sep 14 '22 16:09 Furqan2

There is still same pitch issue

Furqan2 avatar Sep 15 '22 06:09 Furqan2

On the demo, which room do you see the issue?

antoine92190 avatar Sep 15 '22 06:09 antoine92190

"Professor" and "dsds" both .... I have check my S3 bucket also the stored Audio pitch is high as compare to original voice.

Furqan2 avatar Sep 15 '22 06:09 Furqan2

I have the same issue on my side. I'm using vue2. Can I use any configuration of bitrate or something as prop (audio-bit-rate and/or audio-sample-rate) that improve the audio performance? I'm new in this audio stuff...! Thanks

vladimirgomezf avatar Jan 12 '23 15:01 vladimirgomezf

I think the audio code is defective. We should find a better alternative to it. Anyone is welcome to work on that, otherwise I will try to fix it when I have time

antoine92190 avatar Jan 12 '23 21:01 antoine92190

diff --git a/src/utils/recorder.js b/src/utils/recorder.js
index 8f73995..535bfc9 100644
--- a/src/utils/recorder.js
+++ b/src/utils/recorder.js
@@ -44,10 +44,6 @@ export default class {
 
 		this.isPause = false
 		this.isRecording = true
-
-		if (!this.lameEncoder) {
-			this.lameEncoder = new Mp3Encoder(this.encoderOptions)
-		}
 	}
 
 	stop() {
@@ -90,6 +86,20 @@ export default class {
 		this.processor = this.context.createScriptProcessor(this.bufferSize, 1, 1)
 		this.stream = stream
 
+		const sampleRate = stream.getAudioTracks()[0].getSettings().sampleRate
+
+		if (sampleRate !== this.encoderOptions.sampleRate) {
+			this.encoderOptions.sampleRate = stream
+				.getAudioTracks()[0]
+				.getSettings().sampleRate
+
+			this.lameEncoder = new Mp3Encoder(this.encoderOptions)
+		}
+
+		if (!this.lameEncoder) {
+			this.lameEncoder = new Mp3Encoder(this.encoderOptions)
+		}
+
 		this.processor.onaudioprocess = ev => {
 			const sample = ev.inputBuffer.getChannelData(0)
 			let sum = 0.0

For explanation, this actually uses the sampleRate of the microphone, not a fixed one.

TheNoim avatar Feb 06 '23 10:02 TheNoim

@antoine92190 did you find the solution for this ?

Furqan2 avatar Jun 22 '23 12:06 Furqan2

I'm now also getting a deprecation error in the latest version of Chrome [Deprecation] The ScriptProcessorNode is deprecated. Use AudioWorkletNode instead.

And yes my audio pitch is also wrong.. it makes me sound like a chipmunk.

@antoine92190 any chance you will implement @TheNoim's fix?

vesper8 avatar Dec 04 '23 11:12 vesper8