Change How Self-Voicing Pronounces Words?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
cucumbird
Newbie
Posts: 4
Joined: Fri Mar 23, 2018 9:02 pm
Contact:

Change How Self-Voicing Pronounces Words?

#1 Post by cucumbird »

Is it possible to change how self-voicing pronounces a word? There are names in my script that self-voicing can't handle, but I think if I could just change what self-voicing is trying to read, it would fix it.

For example:
Is there some way to set self-voicing to consistently read "hermione" as "hermy one" every time the name comes up?

I think this might be possible through the "alternative text" function, but honestly I'm a bit confused as to how it works.

Thanks!

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Change How Self-Voicing Pronounces Words?

#2 Post by Remix »

It is not an easy one to do afaik as there does not seem to be a function or map that does it all automatically based on words in the dialogue.

If anyone does want to explore further, you eventually want to change the what_alt of the line, e.g:

"Hermione" (what_alt="A different spoken line")
Frameworks & Scriptlets:

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2401
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Change How Self-Voicing Pronounces Words?

#3 Post by Ocelot »

Self-voicing is not a replacement for voiced dialogue. It is merely a tool for visually impaired to be able to access your game at all. In fact RenPy does not voice anything. It is merely accesses speech synthesis API of OS it is running on, so any changes you want to make should be done on end-user OS. Which is not feasible.
< < insert Rick Cook quote here > >

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Change How Self-Voicing Pronounces Words?

#4 Post by Remix »

A rather *hacky* kludge:

Code: Select all

init -1 python:
    voice_map = {
        'hermione' : 'Emma Watson',
        'harry' : 'Daniel Rad cliff',
    }

    def voice_substitute(*args, **kwargs):
        what_alt = str(args[1]).lower()
        for k in voice_map:
            what_alt = what_alt.replace(
                "{0} ".format(k),
                "{0} ".format(voice_map[k])).replace(
                " {0}".format(k),
                " {0}".format(voice_map[k]))
        if what_alt != str(args[1]).lower():
            # substituted
            kwargs.get('what_args', {}).update({'alt':what_alt})
        return renpy.show_display_say(*args, **kwargs)

# this character has her dialogue (the 'what' part) altered on the fly
define h = Character("Hermione", show_function=voice_substitute)

label start:
    # shows these words 
    # and yet autovoice says "Daniel Radcliffe fancies Emma Watson"
    h "Harry fancies Hermione"
    return
Note: The mapping function simply does string replace if it finds the key with a space before or after... tweak/improve as wanted
Frameworks & Scriptlets:

cucumbird
Newbie
Posts: 4
Joined: Fri Mar 23, 2018 9:02 pm
Contact:

Re: Change How Self-Voicing Pronounces Words?

#5 Post by cucumbird »

Remix, thanks for your work! :)

The code you provided does change how self-voicing pronounces words, but for whatever reason, once it's activated, lines that don't contain any terms that need to be changed are no longer voiced.

So, for example:

Code: Select all

label start:
#self-voicing works normally
    h "Test line."
#self-voicing reads: "Daniel Radcliffe fancies Emma Watson"
    h "Harry fancies Hermione."
#self-voicing says nothing
    h "Nobody fancies anyone."
#self-voicing says "I am Daniel Radcliffe"
    h "I am Harry."
    return
Furthermore, if I then restart the game, Hermione's first line ("Test line") is voiced as "I am Daniel Radcliffe."

My game is pretty short (and I have very little coding experience), so I might just do the what_alts by hand, but if you come up with a solution for the above issue I'd love to see it.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3792
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Change How Self-Voicing Pronounces Words?

#6 Post by Imperf3kt »

I seem to recall I just did something like this once: (Cannot test if it works as I remember from here.)

Code: Select all


define dumbledore = "Dumbledore" alt "dumb bell door"


label start:
    harry "Professor [dumbledore]."
It works fine with screens, but I haven't tried it with say statements yet... That I recall. I think I actually did.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

cucumbird
Newbie
Posts: 4
Joined: Fri Mar 23, 2018 9:02 pm
Contact:

Re: Change How Self-Voicing Pronounces Words?

#7 Post by cucumbird »

Imperf3kt wrote: Sun Mar 25, 2018 10:18 pm I seem to recall I just did something like this once: (Cannot test if it works as I remember from here.)

Code: Select all


define dumbledore = "Dumbledore" alt "dumb bell door"


label start:
    harry "Professor [dumbledore]."
It works fine with screens, but I haven't tried it with say statements yet... That I recall. I think I actually did.
Unfortunately this is not valid syntax. I tried:

Code: Select all


define dumbledore = "Dumbledore" (what_alt="dumb bell door")


label start:
    harry "Professor [dumbledore]."
However, the above returns the error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 1, in script
    define dumbledore = "Dumbledore" (what_alt="dumb bell door")
  File "game/script.rpy", line 1, in <module>
    define dumbledore = "Dumbledore" (what_alt="dumb bell door")
TypeError: 'unicode' object is not callable

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 1, in script
    define dumbledore = "Dumbledore" (what_alt="dumb bell door")
  File "C:\Users\Armin\Desktop\OneDrive - The University of Western Ontario\renpy-6.99.13-sdk\renpy\ast.py", line 1912, in execute
    value = renpy.python.py_eval_bytecode(self.code.bytecode)
  File "C:\Users\Armin\Desktop\OneDrive - The University of Western Ontario\renpy-6.99.13-sdk\renpy\python.py", line 1828, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/script.rpy", line 1, in <module>
    define dumbledore = "Dumbledore" (what_alt="dumb bell door")
TypeError: 'unicode' object is not callable

Windows-8-6.2.9200
Ren'Py 6.99.14.3135
TEST 1.0

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3792
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Change How Self-Voicing Pronounces Words?

#8 Post by Imperf3kt »

Hmm, I don't know where I 'remembered' that from, but checking the project I was sure I used it in, I don't see it anywhere. Am I losing my mind :shock:
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Change How Self-Voicing Pronounces Words?

#9 Post by Remix »

You might have used:

define dumbledore = Text( "Dumbledore", alt="dum ball door" )

or something similar.

Give me a while to test a few bits and I will try to find what works...
Frameworks & Scriptlets:

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Change How Self-Voicing Pronounces Words?

#10 Post by Remix »

Not getting anywhere with this, so just a quick fix for my remap function:

Code: Select all

    def voice_substitute(*args, **kwargs):
        what_alt = str(args[1]).lower()
        for k in voice_map:
            what_alt = what_alt.replace(
                "{0} ".format(k),
                "{0} ".format(voice_map[k])).replace(
                " {0}".format(k),
                " {0}".format(voice_map[k]))
        kwargs.get('what_args', {}).update({'alt':what_alt})
        return renpy.show_display_say(*args, **kwargs)
Frameworks & Scriptlets:

cucumbird
Newbie
Posts: 4
Joined: Fri Mar 23, 2018 9:02 pm
Contact:

Re: Change How Self-Voicing Pronounces Words?

#11 Post by cucumbird »

Imperf3kt, I've "remembered" similar things in the past, no worries :P Maybe you wanted to use it but it turned out not to work?

Remix, thanks again, it works perfectly!

Is there a way to make it replace all text, or do I have to individually use the function with each character? Also, is it only possible to use this function with dialogue, or would it be possible to use with screens, etc.?

Rekoija
Newbie
Posts: 15
Joined: Wed Nov 20, 2019 3:19 pm
Contact:

Re: Change How Self-Voicing Pronounces Words?

#12 Post by Rekoija »

the biggest problem here is, that it doesn't care about the name of the person speaking.
so if Hermione is speaking, it will read the name as Hermione, and then change it to Emma Watson when she says it.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Change How Self-Voicing Pronounces Words?

#13 Post by PyTom »

Although I don't know when 7.4 will be released, I've added the {noalt} text tag to take care of this. In conjuction with the also unreleased {alt} tag, this would let you do:

Code: Select all

"{noalt}Dumbledore{/noalt}{alt}Dumb bell dore{/alt}"
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: No registered users