connectToAnalyser not available on audioEngine in TS

Why is connectToAnalyser not available from BABYLON.Engine.audioEngine?

It works in Playground, but on a local machine in Visual Studio code, the method does not show in auto-completion. The code is like this:

import * as BABYLON from 'babylonjs';

class Music {
    private _music: BABYLON.Sound
    private _analyser: BABYLON.Analyser

    constructor(scene: BABYLON.Scene) {
        this._music = new BABYLON.Sound(
            "Music", 
            "//www.babylonjs.com/demos/AudioAnalyser/cosmosis.mp3",
            scene, null, { streaming: true, autoplay: true })   

        this._analyser = new BABYLON.Analyser(scene)
        BABYLON.Engine.audioEngine.connectToAnalyser(this._analyser)
        this._analyser.FFT_SIZE = 32
        this._analyser.SMOOTHING = 0.9
    }

    update() {
        let fft = this._analyser.getByteFrequencyData()
        return(fft)
    }

}

and the compiler returned errors:

ERROR in D:\myBabylon\Eight\src\my-scene.ts
./src/my-scene.ts
[tsl] ERROR in D:\myBabylon\Eight\src\my-scene.ts(14,36)
      TS2339: Property 'connectToAnalyser' does not exist on type 'IAudioEngine'.

Any help is greatly appreciated!

Hey @icezee, welcome to the Babylon family. Great to have you here.

Have you seen this page on how to use the analyzer?
https://doc.babylonjs.com/how_to/playing_sounds_and_music#using-the-analyser

Is it just a problem of it not working locally?

I did go through this document, and I also glanced through the source code audioEngine.ts on github. Playground example works fine, the problem only happens locally.

Thank you very much @PirateJC

Hmm…I think this one will likely require some of our bigger guns to help figure out. Pinging @Evgeni_Popov and @sebavan to help.

I just push my code to github.

I appreciate your help @PirateJC

You should try to use our latest preview, this has been introduced for our next 4.2 release if I remember well.

2 Likes

That did it! @sebavan @PirateJC

I write it down here, in case it is helpful for somebody else who needs to switch to the latest preview.
Basically,
npm uninstall babylonjs -D
then
npm install babylonjs@preview -D

2 Likes