Text to speech

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
togFox
Party member
Posts: 835
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Text to speech

Post by togFox »

Much googling tells me TTS is a very under-developed space for lua and Love and the best I could find was this command line app that can run locally:

https://github.com/espeak-ng/espeak-ng/ ... s/index.md

I've never thought about how I might have my game in Love2d doing the regular game loop thing and then occasionally executing a command line outside the program.

Let's assume the command line is visually hidden and non-interrupting. Would launching a command line program with command and parameters from Love2d be possible?

I'm expecting a less than stellar gaming experience but might be a fun experiment.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
User avatar
BrotSagtMist
Party member
Posts: 665
Joined: Fri Aug 06, 2021 10:30 pm

Re: Text to speech

Post by BrotSagtMist »

Congrats to your 666th post. :D

What do you ask here? Having löve run another program constantly in the background?
That would be io.popen inside a thread, not too hard.
In that case it doesnt matter what language it is in anyway.
obey
User avatar
BrotSagtMist
Party member
Posts: 665
Joined: Fri Aug 06, 2021 10:30 pm

Re: Text to speech

Post by BrotSagtMist »

I tried with popen to no luck. This works tho, kinda funny.

Code: Select all

local op=print
local channel=love.thread.newChannel()
local tcode=[[ 
channel = ...
repeat
 text=os.execute("espeak '"..channel:demand().."'")
until false
]]
Lthread = love.thread.newThread( tcode )
Lthread:start(channel)

print=function(...)  channel:push(table.concat({...})," ") op(...) end
Tx=""
function love.textinput(t)
 Tx=Tx..t
end
function love.keypressed(_,k)
 if k=="return" then
  print(Tx)
  Tx=""
 end
end
Edit: I missed the buffer for popen:

Code: Select all

local tcode=[[ 
channel = ...
handle=io.popen("espeak","w")
handle:setvbuf ("no")
repeat
 handle:write(channel:demand().."\n")
until false
]]
obey
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Text to speech

Post by zorg »

If you don't care much about quality (that is, humanlike sounding output), then technically you could implement a "simple" (relatively, that is) tts like SAM; source code has been available for some time, just needs some porting to lua; there's already a js version available, besides the C source.

Also, löve supports queueable sources, so you can technically generate sound realtime as well; that includes speech.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
togFox
Party member
Posts: 835
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Text to speech

Post by togFox »

Thanks. I have since found what seems to be the real solution (for Windows) and that is to use the speech API:

https://github.com/fiendish/MS_Speech_API_Lua

I've yet to test it.

I'd lose OS portability but was almost certain to happen anyway - unless I used zorgs' approach.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
tourgen
Citizen
Posts: 53
Joined: Sat Mar 18, 2023 12:45 am

Re: Text to speech

Post by tourgen »

togFox wrote: Tue May 02, 2023 2:31 am Thanks. I have since found what seems to be the real solution (for Windows) and that is to use the speech API:

https://github.com/fiendish/MS_Speech_API_Lua

I've yet to test it.

I'd lose OS portability but was almost certain to happen anyway - unless I used zorgs' approach.
Hey! I've used that from C++. It works well. there are additional voices you can use, some are paid. It was a while ago, but I think I had access to some at&t voices at the time.

If I remember right, the MS API package also came with a 'say' command. spawning it from a thread to say a single line of text also worked well.
User avatar
togFox
Party member
Posts: 835
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Text to speech

Post by togFox »

Great. I'm hoping that lua module, and its dependency, will be a no-fuss way of getting some entry- level TTS. ;)
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
Post Reply

Who is online

Users browsing this forum: CutePenguin, Semrush [Bot] and 8 guests