CREATE and FUCK your own AI GIRLFRIEND TRY FOR FREE
x

Ren'Py How-to: Have a "self-voicing" ready game

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,769
15,817
Ren'Py have that marvelous feature that permit to automatically voice any game.

Of course, for the majority of us, it's relatively useless. It don't strictly voice the dialogs, but read the text currently visible in the screen.
But it's precisely what make it useful for all users who are vision impaired. They can still see well enough to enjoy the visual part of your game, but struggle to reading the dialog and narration.
And, of course, there's those who suffer from dyslexia and face too small letters for the dialogs, even when you use an easily readable font.
Despite its limitations, the Self-Voicing feature is a real plus for those persons, and you should take it in count when you make your game. After all, they are players like all the others, they deserve to be in position to enjoy your game.

The main issue is that it's a ready to go feature. It don't know what is part of the interface and what is part of the dialog. Like it don't know what part of the interface is mandatory, and what is not important. Therefore, most game are just not playable with self-voicing... Unless you, devs, care about this right and make them enjoyable. Something that can be done relatively easily and don't need much efforts.


Most of what you need to know is how to use the style property. Three letters that looks insignificant, but will change the life of everyone using Self-Voicing.

By default, the Self-voicing feature will say every text displayed on a screen, whatever it it's through the text, textbutton or label screen statements. And it will say this every single time a new dialog line, or narration line, is displayed. But, if the text have an alt property, then it's the content of that property that will be voiced, in place of the text displayed on the screen.

Let's say that you've an User Interface that display the day and time, Ren'Py will will voice all those information before it voice the dialog or narration line. And it will do it before every single dialog or narration lines.

Therefore, something like this:
Image1.jpg

Will be voice that way: "Day monday, time 12 AM, Unknow girl, Hey, do you want to be my boyfriend".
Then the next dialog line will come, with the MC answering "yes", and this time it's "Day monday, time 12 AM, MC, yes I want".

Annoying, isn't it ?

It's where the alt style property take all it's sense and meaning.
The code for my example screen is basic:
Python:
screen whatever():
    vbox:
        text "Day  [day]"
        text "Time: [time]"
And it suffice of a little nothing to turn it compliant with self-voicing:
Python:
screen whatever():
    vbox:
        text "Day  [day]":
            alt ""
        text "Time: [time]"
            alt ""
Now, the text displayed by the screen become silent, and the player will hear "Unknow girl, Hey, do you want to be my boyfriend", followed by "MC yes I want".


Just this is a great improvement, but you can, and should, go further.
"Unknow girl, Hey, do you want to be my boyfriend", it don't really sound good, right ? Something like "Unknow girl is saying: Hey, do you want to be my boyfriend" would be better. And, it happen that you can also do this, and without need for much effort. You only need to make two really small changes.

Firstly, tweak a bit the "namebox" style. It's the style used to display the name of the character saying the dialog line. Just add this anywhere in your code:
Python:
style namebox:
    alt ""
Now the name of the character will not be voiced anymore... What don't looks like an improvement, I know. But the magic come from the second change.

Open the file "screen.rpy" and look at the screen named "say". It's the one that display the dialogs.
Inside you'll fine that like: text what id "what"
Change it in this:
Python:
        text what:
            id "what"
            alt "{} is saying: {}".format( who, what )
And it's done, now when the self-voicing is enabled, Ren'Py will not anymore say "Unknow girl, Hey, do you want to be my boyfriend", but the "Unknow girl is saying: Hey, do you want to be my boyfriend" that is more natural.


All this is already great, the self-voicing isn't anymore polluted by useless text, and the dialog lines are voiced in a more natural way.
But there's still an issue, right ? If you made an User Interface displaying the day and time, it's because they are information that the player need to know... And now they aren't voiced anymore.

Don't worry, there's an alternative for this too, the character.
It's a special character, that exist by default and, like for narrator have no name. But this character is really special, because it will only be used if the self-voicing is enabled. So, all you have to do is to use it in order to voice the most important changes in the game.

Let's say that you use a basic day system:
Python:
# The string that will be displayed by your User Interface.
define dayToString = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]

label changeDay:
    $ day += 1   # One more day.
    $ day %= 7  # cycle between 0 and 6.
    return   # return to the game flow.
To make this self-voicing compliant, you just need a small change:
Python:
define dayToString = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]

label changeDay:
    $ day += 1
    $ day %= 7
    $ dayAsString = dayToString[day] # Get the day as text.
    alt "A new day starts, it's now [dayAsString]."  # Display the day as text *only* if self-voicing is enabled.
    return
For players who don't use the self-voicing, nothing will change. But for those who use it, they'll see, and more importantly hear, "A new day starts, it's now Thuesday", or whatever the day will effectively be.

If your code to handle the day is done purely in Python, you just have to use the function: renpy.say( alt, "Text to display and voice if the self-voicing feature is enabled." )

And the same should be done for the time of the day, for the money spent or earned, as well as for the points earned, or lost. Every value that is shown by your User Interface should be handled that way, with an alt narration line warning the player using self-voicing about the change.


There's more that could be said in regard of compliance for players suffering from an impaired vision, but on that How To I wanted to focus on the most important part, the self-voicing. And, regarding it, you now know everything there's to know, what mean that you don't anymore have an excuse to release games that aren't compatible with that feature.
 

Turning Tricks

Rendering Fantasies
Game Developer
Apr 9, 2022
1,264
2,393
Ren'Py have that marvelous feature that permit to automatically voice any game.

Of course, for the majority of us, it's relatively useless. It don't strictly voice the dialogs, but read the text currently visible in the screen.
But it's precisely what make it useful for all users who are vision impaired. They can still see well enough to enjoy the visual part of your game, but struggle to reading the dialog and narration.
And, of course, there's those who suffer from dyslexia and face too small letters for the dialogs, even when you use an easily readable font.
Despite its limitations, the Self-Voicing feature is a real plus for those persons, and you should take it in count when you make your game. After all, they are players like all the others, they deserve to be in position to enjoy your game.

The main issue is that it's a ready to go feature. It don't know what is part of the interface and what is part of the dialog. Like it don't know what part of the interface is mandatory, and what is not important. Therefore, most game are just not playable with self-voicing... Unless you, devs, care about this right and make them enjoyable. Something that can be done relatively easily and don't need much efforts.


Most of what you need to know is how to use the style property. Three letters that looks insignificant, but will change the life of everyone using Self-Voicing.

By default, the Self-voicing feature will say every text displayed on a screen, whatever it it's through the text, textbutton or label screen statements. And it will say this every single time a new dialog line, or narration line, is displayed. But, if the text have an alt property, then it's the content of that property that will be voiced, in place of the text displayed on the screen.

Let's say that you've an User Interface that display the day and time, Ren'Py will will voice all those information before it voice the dialog or narration line. And it will do it before every single dialog or narration lines.

Therefore, something like this:
View attachment 3551174

Will be voice that way: "Day monday, time 12 AM, Unknow girl, Hey, do you want to be my boyfriend".
Then the next dialog line will come, with the MC answering "yes", and this time it's "Day monday, time 12 AM, MC, yes I want".

Annoying, isn't it ?

It's where the alt style property take all it's sense and meaning.
The code for my example screen is basic:
Python:
screen whatever():
    vbox:
        text "Day  [day]"
        text "Time: [time]"
And it suffice of a little nothing to turn it compliant with self-voicing:
Python:
screen whatever():
    vbox:
        text "Day  [day]":
            alt ""
        text "Time: [time]"
            alt ""
Now, the text displayed by the screen become silent, and the player will hear "Unknow girl, Hey, do you want to be my boyfriend", followed by "MC yes I want".


Just this is a great improvement, but you can, and should, go further.
"Unknow girl, Hey, do you want to be my boyfriend", it don't really sound good, right ? Something like "Unknow girl is saying: Hey, do you want to be my boyfriend" would be better. And, it happen that you can also do this, and without need for much effort. You only need to make two really small changes.

Firstly, tweak a bit the "namebox" style. It's the style used to display the name of the character saying the dialog line. Just add this anywhere in your code:
Python:
style namebox:
    alt ""
Now the name of the character will not be voiced anymore... What don't looks like an improvement, I know. But the magic come from the second change.

Open the file "screen.rpy" and look at the screen named "say". It's the one that display the dialogs.
Inside you'll fine that like: text what id "what"
Change it in this:
Python:
        text what:
            id "what"
            alt "{} is saying: {}".format( who, what )
And it's done, now when the self-voicing is enabled, Ren'Py will not anymore say "Unknow girl, Hey, do you want to be my boyfriend", but the "Unknow girl is saying: Hey, do you want to be my boyfriend" that is more natural.


All this is already great, the self-voicing isn't anymore polluted by useless text, and the dialog lines are voiced in a more natural way.
But there's still an issue, right ? If you made an User Interface displaying the day and time, it's because they are information that the player need to know... And now they aren't voiced anymore.

Don't worry, there's an alternative for this too, the character.
It's a special character, that exist by default and, like for narrator have no name. But this character is really special, because it will only be used if the self-voicing is enabled. So, all you have to do is to use it in order to voice the most important changes in the game.

Let's say that you use a basic day system:
Python:
# The string that will be displayed by your User Interface.
define dayToString = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]

label changeDay:
    $ day += 1   # One more day.
    $ day %= 7  # cycle between 0 and 6.
    return   # return to the game flow.
To make this self-voicing compliant, you just need a small change:
Python:
define dayToString = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]

label changeDay:
    $ day += 1
    $ day %= 7
    $ dayAsString = dayToString[day] # Get the day as text.
    alt "A new day starts, it's now [dayAsString]."  # Display the day as text *only* if self-voicing is enabled.
    return
For players who don't use the self-voicing, nothing will change. But for those who use it, they'll see, and more importantly hear, "A new day starts, it's now Thuesday", or whatever the day will effectively be.

If your code to handle the day is done purely in Python, you just have to use the function: renpy.say( alt, "Text to display and voice if the self-voicing feature is enabled." )

And the same should be done for the time of the day, for the money spent or earned, as well as for the points earned, or lost. Every value that is shown by your User Interface should be handled that way, with an alt narration line warning the player using self-voicing about the change.


There's more that could be said in regard of compliance for players suffering from an impaired vision, but on that How To I wanted to focus on the most important part, the self-voicing. And, regarding it, you now know everything there's to know, what mean that you don't anymore have an excuse to release games that aren't compatible with that feature.
This is awesome. Thanks anne O'nymous!

When I first started making my character definitions (ages ago) I copied some code from another game and it uses the alt tag for things like "thinking" or "whispering". I tested it in the very first builds I made but then basically just forgot about it since I don't use the Voice over function.

I just tested it again and I realize that the self-voicing does what you used as an example of there. It says the Day number and the Day of the week that I display in the upper left.

I also just realized that the original what_alt code I used for thinking and whispering, is causing self-voicing to "double up". So, because I display the dialogue as "Character thinking..." and there's also the what_alt tag, the voice will say "Mark thinking ... Thinks <dialogue>"

I mustn't have many vision-impaired players, because nobody has every complained about this.

I'm going to fix it for my next release though. (a lot of Cut & Pasting code snippets in my future... :eek:)

I'm glad I ventured into this forum, lol.
 

genen850

New Member
Apr 6, 2024
1
1
So...I followed you down this rabbit hole as well. I didn't see in your post (could have missed it as I only scanned it) on how to change the default voice used if it isn't already coded by the dev. Say what you may but its kind of weird having Microsoft David read me an adult novel. So I learned that if you "Unren" a game you have access to the "options.rpy" file. Then, for logics sake, in the section for "sounds and audio" enter define config.tts_voice = "Hazel". Substitute Hazel for the name of whatever voice pack you chose in Windows speech options. You can download additional packs to get the british female voice Hazel. Much better if you ask me.
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,769
15,817
I didn't see in your post (could have missed it as I only scanned it) on how to change the default voice used if it isn't already coded by the dev.
I haven't covered it for two reasons:

Firstly, because the name of the voice fully depend on the OS and, at least for Linux, what software is registered as voice synthesizer. I also kind of remember that Windows can have more voices than the default one ; but it's 9:30 AM and I just come back from a long day (and night) at works, so don't quote me on this.

Secondly because normally Ren'Py do not choice the voice, letting the system do it itself. What mean that users that are in real need of it already have configured their system with the voice they prefer, and will have it used by Ren'Py. Therefore, telling devs how to change it didn't felt right in my mind ; user choice should always have the last word.


This said, yeah, I should probably still have added a footnote explaining this. But, like I'm not as young in real life than I still am in my mind, and just finish a 26h day, it's probably better if I don't do it right now ;)


Say what you may but its kind of weird having Microsoft David read me an adult novel.
Strange, it's a girl voice that I have with my Windows 10. So, I guess that for Windows it also depend on the version you have, and possibly its language.


So I learned that if you "Unren" a game you have access to the "options.rpy" file. Then, for logics sake, in the section for "sounds and audio" enter define config.tts_voice = "Hazel".
You don't need unren for that. Just create a "myVoice.rpy" file, put:
Python:
init python:
    config.tts_voice = "Hazel" # or whatever have your preference
inside, then drop the file in the "game" directory (where there's the rpa/rpy/rpyc files), and it will do the same, overriding the default configuration by yours.
 
  • Like
Reactions: genen850