I had an issue where I was trying to play a sound when an object was destroyed but I couldn't hear those sounds. The problem was that by calling queue_free to remove the object, the playing sound terminated instantly as well.
It looked like the way to solve this (your situation might be something similar) was to have an AudioStreamPlayer someplace else in the Scene Tree and send it signals. I was trying to plug this together, when I found this bit of code for an audio manager script: https://kidscancode.org/godot_recipes/audio/audio_manager/
extends Node
var num_players = 8
var bus = "master"
var available = [] # The available players.
var queue = [] # The queue of sounds to play.
func _ready():
# Create the pool of AudioStreamPlayer nodes.
for i in num_players:
var p = AudioStreamPlayer.new()
add_child(p)
available.append(p)
p.connect("finished", self, "_on_stream_finished", [p])
p.bus = bus
func _on_stream_finished(stream):
# When finished playing a stream, make the player available again.
available.append(stream)
func play(sound_path):
queue.append(sound_path)
func _process(delta):
# Play a queued sound if any players are available.
if not queue.empty() and not available.empty():
available[0].stream = load(queue.pop_front())
available[0].play()
available.pop_front()
I named this script AudioManager and set it to autoload in Project Settings. Now I just need to "AudioManager.play("res://sound.mp3") from anywhere in the scene tree. This works very nicely and is how I plan to set up all my Godot audio from now on. You might want to try it because it sounds like something might be terminating your sound prematurely.