awaymsg
awaymsg

Reputation: 31

How to update audio from a source in Vue?

This is probably a dumb question, but I'm pretty new to this. I'm probably going about it in very wrong ways hah.

So I wrote a backend that learns from a text file and generates sentences. It will also generate an audio version of that sentence. At first, I had a lot of trouble using the Audio object to actually load that audio file, until I realized that the relative path is relative to the dist folder.

The code is pretty simple for playing the file. I think I'm not understanding something about how it works (I just have the response bring back a boolean for now)

if (response.data) {
    this.audio = new Audio('text.mp3')
    this.audio.play()
}

The generated audio just overwrites the same file, which is now in the dist folder. It will play the audio file when you click the button. However, after you generate another sentence (which then overwrites the audio file), and you click the play button, it will play the original audio, not the new one, even though the audio file is def updated.

I kind of have no clue as to why it is not creating a new instance of Audio with the new version of the file? I feel like the memory is not being freed or something and javascript is trying to take a shortcut instead of instantiating a new object, but idk how to get around this.

Thanks!

--edit-- Ok it's def due to memory not being freed, bc after waiting a bit and going back to it, the audio was updated >.>

Upvotes: 2

Views: 356

Answers (1)

awaymsg
awaymsg

Reputation: 31

Resolved

Needed to break cache w/ query string like "test.mp3?123"

Upvotes: 1

Related Questions