0 votes
by (1.2k points)
As a bit of a change of pace I decided to build something frivolous - an emulator for SMS conversations between characters.

One of the things I'm playing around with is the idea of the typing noises corresponding to the length of the message. I've created three noises with varying amounts of silence in them that can be randomly played in sequence to emulate the effect (with a separate audio file for the space character).

As far as I can tell though once a playlist has one copy of an audio file that's it. If it's not possible with the current functionality I'll just fake it with a premade audio clip but I thought I'd ask as it intrigued me!

(Sugarcube 2.20.0 and Twine 2.1.3.)

Thanks!

1 Answer

0 votes
by (68.6k points)

Playlists created via <<createplaylist>> may contain as many copies of a track as you'd like.  The only issue may be that if you plan on playing the same track back-to-back, then you may need to make each directly successive entry a copy, via the copy keyword.  For example:

<<createplaylist "some_playlist">>
	<<track "typing_A">>
	<<track "typing_C">>
	<<track "typing_B">>
	<<track "typing_A">>
	<<track "typing_A" copy>>
	<<track "typing_A" copy>>
	<<track "typing_B">>
	<<track "typing_C">>
<</createplaylist>>

 

by (1.2k points)

Hmm, I was already using "copy" so presumably there's something else I'm messing up. Here's the code for my test passage:

<<nobr>>

<<cacheaudio "singleKeyStroke0" "singleKeyStroke1.mp3">>
<<cacheaudio "singleKeyStroke1" "singleKeyStroke2.mp3">>
<<cacheaudio "singleKeyStroke2" "singleKeyStroke3.mp3">>
<<cacheaudio "spaceKeyStroke" "spaceKeyStroke.mp3">>

<<set _message to "Magna enim beef ribs, ham sed beef deserunt commodo picanha pastrami venison swine meatloaf. Nulla consectetur non sausage ham esse corned beef velit exercitation aute enim picanha pork belly ham hock. Burgdoggen dolore mollit tongue. Strip steak in ipsum in et est in do jowl consectetur. Ham hock drumstick reprehenderit alcatra, consequat shoulder porchetta enim pork loin occaecat turducken pork venison esse. Ea bacon irure t-bone pig consectetur, ham tongue ipsum in.">>

<<createplaylist "SMStyping">>

<<for _i to 0; _i lt _message.length; _i++>>
	<<if _message[_i] eq " ">>
		<<track "spaceKeyStroke" copy>>
	<<else>>
			<<switch random(0,2)>>
		<<case 0>>
				<<track "singleKeyStroke0" copy>>
		<<case 1>>
				<<track "singleKeyStroke1" copy>>
		<<case 2>>
				<<track "singleKeyStroke2" copy>>
		<</switch>>
	<</if>>
<</for>>

<</createplaylist>>

<<playlist "SMStyping" play>>

<</nobr>>

Each clip plays once, as far as I can tell, then the playlist ends.

The four audio files can be found here (less than 3kb total).

by (159k points)

Your issues is a result of you trying to call macros that are invalid within the body of a  <<createplaylist>> macro, if you look at it's documentation you will see that it only accepts <<track>> macros.

What is really happening in your example is that every thing other than the four <<track>> macro calls is being ignored, which is why you always hear the audio sounds four times no mater how many elements the _message Array actually has.

You could possibly use the Stupid Print Trick™ to overcome this issue like so:

<<set _buffer to '<<createplaylist "SMStyping">>'>>
<<for _i to 0; _i lt _message.length; _i++>>
	<<if _message[_i] eq " ">>
		<<set _buffer += '<<track "spaceKeyStroke" copy>>'>>
	<<else>>
		<<switch random(0,2)>>
		<<case 0>>
			<<set _buffer += '<<track "singleKeyStroke0" copy>>'>>
		<<case 1>>
			<<set _buffer += '<<track "singleKeyStroke1" copy>>'>>
		<<case 2>>
			<<set _buffer += '<<track "singleKeyStroke2" copy>>'>>
		<</switch>>
	<</if>>
<</for>>
<<set _buffer += "<</createplaylist>>">>
<<print _buffer>>

 

by (1.2k points)
Excellent! That totally works!

I'm surprised one can't use clever logic to add things to a playlist without having to use <<print>> though.

Now to go edit the sound files to be shorter as the typing does rather go on a bit!
...