Playing multiple tts voices simultaneously

Hello all, I would love to be able to play multiple tts voices Simultaneously. I think we can d do this in swift, is it possible to implement this in codea as well?

Codea’s built-in API speech.say() only handles one thing at a time but there are a couple other options:

  • it may be possible through the Objective-C bridge. iOS’s AVSpeechSynthesizer allows you to create multiple synthesizer instances, and each can speak independently. Since Codea can instantiate and call Objective-C classes, you could create two or more AVSpeechSynthesizer objects and have them speak at the same time.
  • I think @Steppers created “true multithreaded” possibilities in Codea, I’m not sure how it works but I thinks it’s in the Codea+ library on WebRepo. Again I’m not sure how it works but if each thread is independent then maybe you could in that case get two speech.say() commands playing at the same time.

Does any of that help? What are you trying to do?

Thanks a ton, i got it working through the objc! =)

I wanted to make a chorus. I tried making the normal tts voices sing before but that never really worked out, but recently I noticed there are a couple new more melodic voices, very close to actual singing.

1 Like

Ooo that sounds really fun! Is it something you can share?

Sure!

function setup()

voices = {
    "com.apple.speech.synthesis.voice.Albert",
    "com.apple.speech.synthesis.voice.BadNews",
    "com.apple.speech.synthesis.voice.Bahh",
    "com.apple.speech.synthesis.voice.Bells",
    "com.apple.speech.synthesis.voice.Boing",
    "com.apple.speech.synthesis.voice.Bubbles",
    "com.apple.speech.synthesis.voice.Cellos",
    "com.apple.speech.synthesis.voice.Deranged",
    "com.apple.speech.synthesis.voice.Fred",
    "com.apple.speech.synthesis.voice.GoodNews",
    "com.apple.speech.synthesis.voice.Hysterical",
    "com.apple.speech.synthesis.voice.Junior",
    "com.apple.speech.synthesis.voice.Kathy",
    "com.apple.speech.synthesis.voice.Organ",
    "com.apple.speech.synthesis.voice.Princess",
    "com.apple.speech.synthesis.voice.Ralph",
    "com.apple.speech.synthesis.voice.Trinoids",
    "com.apple.speech.synthesis.voice.Whisper",
    "com.apple.speech.synthesis.voice.Zarvox"
}

chants = {
    "aaaaaaaaaaaaaaaaaaaaaheho",
    "ooooohaaahuhuhaaaaheeeehoho",
    "uuuuuuuuuu",
    "eeeeeeeeeho",
    "iiiiiiiiiiiho",
    "zzzzezozaaa",
    "yyyyyyyyya",
    "what a wonderful world"
}

chant = chants[2]

numVoices = 3

-- 7, 10, 14
voice = voices[14]

synths = {}
utters = {}


voiceObj = objc.AVSpeechSynthesisVoice:voiceWithIdentifier_(voice)

for i = 1, numVoices do
    
    synths[i] = objc.AVSpeechSynthesizer()
    
    utters[i] = objc.AVSpeechUtterance:alloc()
    utters[i]:initWithString_(chant)
    
    utters[i].voice = voiceObj
    
    -- random pitch variation around normal
    utters[i].pitchMultiplier = 1 + math.random(-10,0)/100
    
    -- slightly different speaking rates
    --utters[i].rate = 0.45 + math.random(-10,10)/100
    
    -- stagger entrances
    tween.delay(i * 0.005, function()
        synths[i]:speakUtterance_(utters[i])
    end)
    
end

end

That’s fun and definitely a bit spooky!

Is it for any specific project?

Not yet really, i just always wanted to try simple procedural tts songs, which i gave up on, but recently i discovered this bunch of melodic voice and wanted to experiment with them. Procedural speech has always been s fascination of mine, from the currently available tts voices to the voder from way back when.

There’s a couple of cool demonstrations of the voder on YouTube: https://m.youtube.com/watch?v=5hyI_dM5cGo&pp=ygUKVm9kZXIgZGVtb9IHCQloAqO1ajebQw%3D%3D&ra=m

And the classic Daisy from 2001 a space odyssey

But my favorites are those old vic20 voices which were barely intelligible and could generally only be understood by showing the actual text alongside: https://m.youtube.com/watch?v=BFo7IEy92No&list=RDBFo7IEy92No&start_radio=1&pp=ygUScHdwIHRoZSBuZXh0IGxldmVsoAcB0gcJCb4LAYcqIYzv&ra=m

And another one, slightly more intelligible: https://m.youtube.com/watch?v=2SdGkkp1aq8

I played this in front of people and got weird looks. Thanks for the cool project @Kirl

I remember way back in the days of the Atari 2600 a friend and I would randomly snoop around BBSes looking for various things to download and we downloaded a file that would play some guitar and words “girl you really got me” from the Van Halen version.

We were both blown away that a computer could make something that sounded so much like speech and we ran to his uncle who knew nothing about computers and played it for him.

He was completely unimpressed and we were deflated.

We asked him “don’t you see how cool this is?“ and he shrugged and said “Not really. I just assume computers can do anything.“