Can't import audio files

Hello everyone,

I’m working on an AR project in 8th Wall Studio (Beta). The idea is the player will be able to walk around outside and clay pigeons will spawn around them and the player can “shoot” them.

I have this system more or less working, so I thought it would be a good idea to start adding some audio to it.

import * as deathSound1 from './assets/Audio/kbhp.m4a'
import * as deathSound2 from './assets/Audio/kblp.m4a'
import * as deathSound3 from './assets/Audio/kbn.m4a'

I’m following along with (1) Niantic Studio Workshop: Game Mechanics Basics - YouTube for implementing some audio sounds for when the player has shot one of the clay pigeons.

However, as soon as I add these lines to my clay pigeon component the console gives me the following error:

[tsl] ERROR in /tmp/src/wbd.wonderment-phyics-concept/clayPigeon.ts(3,30)
      TS2307: Cannot find module './assets/Audio/kbhp.m4a' or its corresponding type declarations.

ERROR in /tmp/src/wbd.wonderment-phyics-concept/clayPigeon.ts
./clayPigeon.ts
[tsl] ERROR in /tmp/src/wbd.wonderment-phyics-concept/clayPigeon.ts(4,30)
      TS2307: Cannot find module './assets/Audio/kblp.m4a' or its corresponding type declarations.

ERROR in /tmp/src/wbd.wonderment-phyics-concept/clayPigeon.ts
./clayPigeon.ts
[tsl] ERROR in /tmp/src/wbd.wonderment-phyics-concept/clayPigeon.ts(5,30)
      TS2307: Cannot find module './assets/Audio/kbn.m4a' or its corresponding type declarations.

Now, I honestly feel really silly asking about this because it should be very straightforward.

I’ve also tried to, instead of importing like above, directly implement the audio url path in code like so:

function playDeathSound() {
      const randomChoice = Math.random()
      let audioClipUrl = ''
      if (randomChoice <= 0.33) {
        audioClipUrl = './assets/Audio/kill_bird_normal.m4a'
      } else if (randomChoice >= 0.66) {
        audioClipUrl = './assets/Audio/kill_bird_higher_pitch.m4a'
      } else {
        audioClipUrl = './assets/Audio/kill_bird_lower_pitch.m4a'
      }
      ecs.Audio.set(world, eid, {
        url: audioClipUrl,
      })
      console.log('play death sound: ', audioClipUrl, eid)
    }

This doesn’t throw any errors in the console, but no audio is played either. The console log outputs what I would expect here, being a selected audio file path + which entity it should have triggered on.

Any advice on how I might approach this would be appreciated. Thank you.

The way you’re trying to do it won’t work because it can’t resolve the file paths correctly. Instead, define the death sounds as properties in your component schema like this:

// @asset
deathSound1: ecs.string

In your component, under properties, you’ll be able to select the sound asset from the dropdown. Then, just use component.schema.deathSound1 as your audio path.

Heads up: I’d probably convert those soundfiles from m4a to wav using a tool like Audacity.

Thank you for the response! I’ve tried your solution, but now when my applcation runs the playDeathSound function, the entire application halts and tracking freezes completely.

If I continue to tap on my screen it will still register input, and I’ll still receive raycast hit results. Running in the editor I get the following error:

Uncaught RuntimeError: Aborted(Cannot enlarge memory arrays to size 75161600 bytes (OOM). Either (1) compile with -sINITIAL_MEMORY=X with X higher than the current value 67108864, (2) compile with -sALLOW_MEMORY_GROWTH which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -sABORTING_MALLOC=0)

I disabled calling of the audio cues and I still get this error, so for now I’ve apparently messed something else up. Regardless I appreciate your response and this definitely has pointed me in a direction to look into.

I’ve also converted the audio files I want to use to .wav, only to find out that 8th wall studio doesn’t support .wav files.

Audio | 8th Wall

Ended up moving the funciton for playing my death sounds and resetting location based on player world position to not be inside the statemachine. Relocated to the add feature in ecs.

This seems to have resolved the runtime error I was running into. But the sounds are not audible.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.