This message was deleted.
# helpdesk
s
This message was deleted.
d
It's the former. The audioLevel is coming from the server, which is updated every 500ms. It's useful for somethings, but probably not fast enough to power an animated audio-level widget. It's probably better to analyze the stream locally in that case.
s
You mean analyzing the local and remote streams locally? Sounds interesting 👍 How is that possible, do you have some code good example, links or other hints?
c
Here are my code snippets for a very nice vu meter. You can attach it to any stream.
🔥 1
❤️ 1
Copy code
// setup an audio analyzer
			this.audioContext = new window.AudioContext;
			this.analyser = this.audioContext.createAnalyser();
			this.analyser.fftSize = 32; // minimum
			this.analyser.maxDecibels = 60;
			this.analyser.maxDecibels = 20;
Copy code
onLocalTrackPublished(pub: LocalTrackPublication, participant: LocalParticipant) {
		
	
		if (pub.kind === 'audio') {
			// connect the stream to an analyzer
			let stream = pub.track?.mediaStream;
			if (stream && this.audioContext) {

				let source = this.audioContext?.createMediaStreamSource(stream);
				source?.connect(analyser);
			}
		}
Then setup a timer.
Copy code
this.timer = window.setInterval(() => {
				if (this.analyser && this.analyser.numberOfInputs > 0) {
					let frequencyData = new Uint8Array(1);
					this.analyser.getByteFrequencyData(frequencyData);
					let volume=frequencyData[0] / 1.5;
					
					this.onLocalAudioLevel(volume); // do some graphics stuff with this value
				}
s
Thanks you @creamy-notebook-61404 🙂 🙏