Playing wave files sequentially issue

Hi, Im trying to play sequential wav files. Ive tried Player and sound, both seem to have the same issue which is me not understanding how they work.
When I run the code, only one wave file plays or i can hear which is the last file. Im assuming there running through all files quickly, that's a guess.
I tried using a procedure to play the file, its called every time I want to play the file, but only hear the last file.

Thanks

Show your (relevant) blocks.

1 Like

Hi, thanks, here are two screen shots of the code. As mentioned I only hear 1 WAV file. reading some posts it seems maybe pre-loading the 19 WAV files might solve the problem. Will try that next

Thanks


Hello Thomas

Is 'PlayTune' an extension? It doesn't look right in your Blocks - why would the parameter 'x' be set to 'blank text'? Also, you are using text Blocks for your .wav files but you can instead use App Inventor's media Blocks. Another thing to consider is that .wav files are much bigger than .mp3 - although .wav arguably has better quality, that isn't noticeable on your average Smartphone.

EDIT: It has been pointed out to me that 'PlayTune' is a procedure.
Tip: Give every component a meaningful name - but always retain the component type name e.g. Label_PickedValue, Button_CalcTotal, procedure_PlayTune

The playing of your 'tunes' run into each other - your code isn't waiting for the first to finish before calling the next, so that is why only the last is actually heard. Are they 'long' (a tune or piece of music) or 'short' (a sound effect). Use the Player component for 'long' and Sound component for 'short'.

If the files are to be played in succession, a great solution is to merge them into one file - it's easy to do that with an editor such as Audacity:

... which you can also use to convert from .wav to .mp3.

Snap3

blocks

1 Like

This app needs a global variable Playlist to hold the file names that have not started
their play.

Next playing file should be in slot 1.

Hi thanks for the response. I originally used sound as the wav files are a few seconds. In the sound library I'm not sure what function tells me the wav file is finished.

think of the code as a piano, the sound of the keys is the wav file, 19 keys and a random generator is used to pick the key sequance.

Thanks

...you will need to verify the length of each sound, put those times, in milliseconds, in a Block List and when a sound is played, enable a Clock timer for it's related time in the Block List - or use the Player which does know when the sound has finished.

However, if the sounds are short as you say, each sound can be played over the previous, just like a piano:

Use Player, not Sound.
Player have a event When Player.Completed (not sure if this exact name). in this event, play next wav file. as for which is next, use a list to store wave files and a counter to indicate which one is playing.

Im having a hard time picturing this logic in my head lol. With the attached block image, even though Im checking to see if the play tune has completed, want the code just continue running through all selected wav files untill the last wav file has completed.
Which means the order of the wav files will be differant all the time.

I need to implement a que where each wav file is played in order. eg(wave3.wav, then wave9.wav, then wave2.wav) and so on.
Having a brain strain here lol

Thanks

Thomas

Do not call Player.Start in a for loop or while loop, since you did not give it enough time to play.instead use a Player.Completed event.

1 Like

Hi Thomas - do you mean, although selected randomly, each sound should only be played once?

By the way - convert the .wav files to .mp3

Try this Project:
Piano2.aia (2.7 KB)

Just drag and drop your 19 wav files into the Media tray.

Hi Chris, basically what happens is the user says a sentence which is translated to text. I then calculate how many words are in the sentence.

There is 1 wave file played per word, so if I say "Hello World The Sun is out" there are 6 words.
I then call a random wave file between 1 - 19 for each word.
Then i wait for the next sentence to be spoken and do it all again.

Hope that helps understand what I'm trying to accomplish.
Each wave file is a few seconds long.

Hi Thomas

I had pretty much guessed that - we could have done with that clear explanation in your first post :upside_down_face:

Use the file I have uploaded as a basis - once you understand how it works.

Here is a sample app that tries to sing using the Speech component.
Its queue logic is similar to what you would do with the Player component.

Hi all, thanks for all your help today. I finally found out why Im getting the 701 unable to load error when randomly selecting from 1 to 19 audio files.
Any files over 9 will flag that error, eg (wave3.wav or wave3.mp3) are ok, under 10. if the file chosen was (wave10.wav or wave10.mp3) the error appears and no sound.
Is there a limit to how many audio files you can load. Please see test code. I had each audio file name printed to a label.

Thanks

My mistake, works up to wave10.wav then anything above 10 it errors.
Thanks

Thomas

My mistake again, didn't have files 11 - 19 loaded in my media list lol

Thanks Again for your help

There is a feature in AI2 that builds those text blocks automatically from the Media folder, preloaded with file names.

I don't use Media, so I don't remember where to look for it.

Thanks will check.
Attached is the final blocks that work for sequential playing of files incase someone
else is having a brain freeze like i did lol.
Once again thanks to everyone that helped.

Thomas