Tool Ren'Py Text To Clipboard

oidex

Active Member
Jan 9, 2018
714
1,831
Someone once askes me to help them hook text from RenPy games so he could run it through a translator while playing, without fiddling with the engine itself.
After seeing someone else ask for the same, I though why not upload it here.
Maybe someone has a use for it.

Just drop it into the /game folder and all standard text should be copied to the clipboard in the form of "[Speaker] Text".
You can then have TranslationAggregator or whatever you use auto-grab it from there.

Caveat: It won't copy input prompts (e.g. "Enter you Name").
 

Bober

New Member
Aug 13, 2016
4
2
Thanks a lot, this is great.
I tried to change the voice and speed of the self voicing feature of RenPy many times and failed.
This solves my problem.
 

alma001

Member
Sep 16, 2017
145
68
Hello oidex just wanted to inform you that the script you've made is extremely helpful!

I am a bit visually impaired so I am using it for a text-to-speech program since the built in text-to-speech feature in renpy reads out all menu visible on the screen as well which makes in not usable for many games.

If you have time and would like to, I could advise you two improvements.

One is that it copies the names telling the things as well, which is fine in case of dialogues but in case of a narrative part everything starts with "None" because of it, maybe you could filter this out before putting the text to clipboard.

Another is that if the text contains colored parts (names in many games for example) or images (hearts in many games for example) then the whole code is copied, maybe you can filter these tags out before copying to clipboard.

Here is an example for both, the text in the game is simply "His name is Eric and we have been going out for two years now, since we both started college.":

[None] His name is {color=#0066CC}Eric{/color} and we have been going out for two years now, since we both started college.

But again, your script is already really helpful and thank you for it!

Edit: I've solved both. I am not a programmer at all, so please don't laugh on my code, just did some google research. Let me upload it if anyone in the future will come here and needs these updates. Also, oidex, feel free to come up with a better solution if you think so, and thanks for the idea, I hope you don't take as an insult that I've modified your file.
 
Last edited:

oidex

Active Member
Jan 9, 2018
714
1,831
Hello oidex just wanted to inform you that the script you've made is extremely helpful!

I am a bit visually impaired so I am using it for a text-to-speech program since the built in text-to-speech feature in renpy reads out all menu visible on the screen as well which makes in not usable for many games.

If you have time and would like to, I could advise you two improvements.

One is that it copies the names telling the things as well, which is fine in case of dialogues but in case of a narrative part everything starts with "None" because of it, maybe you could filter this out before putting the text to clipboard.

Another is that if the text contains colored parts (names in many games for example) or images (hearts in many games for example) then the whole code is copied, maybe you can filter these tags out before copying to clipboard.

Here is an example for both, the text in the game is simply "His name is Eric and we have been going out for two years now, since we both started college.":

[None] His name is {color=#0066CC}Eric{/color} and we have been going out for two years now, since we both started college.

But again, your script is already really helpful and thank you for it!

Edit: I've solved both. I am not a programmer at all, so please don't laugh on my code, just did some google research. Let me upload it if anyone in the future will come here and needs these updates. Also, oidex, feel free to come up with a better solution if you think so, and thanks for the idea, I hope you don't take as an insult that I've modified your file.
Looks good to me. I might have precompiled the regex to save a microsecond of execution time but that's just playing around. Also, this is a pirate forum, so you can take, modify and redistribute my stuff however you like, as long as you aren't a dick and charge others for it. ;)
 

Dan5k74

Active Member
Oct 6, 2017
619
3,830
Someone once askes me to help them hook text from RenPy games so he could run it through a translator while playing, without fiddling with the engine itself.
After seeing someone else ask for the same, I though why not upload it here.
Maybe someone has a use for it.

Just drop it into the /game folder and all standard text should be copied to the clipboard in the form of "[Speaker] Text".
You can then have TranslationAggregator or whatever you use auto-grab it from there.

Caveat: It won't copy input prompts (e.g. "Enter you Name").
Thank you for the very useful tool, but I was wondering if it would be possible to create a similar one that could instead hook exclusively the text lines related to the choices present in Renpy games (those in the choice menus, to be clear).
Something like this (let's call it a Playthrough Helper or Choice Recorder) would be very useful to me to greatly speed up the task of creating playtroughs to export as text documents or more simply to record, in a similar type of file, the choices made in a given game path (sometimes I've found myself picking up a game I haven't played in a long time and wondering, "How did I get here? What are the choices I made?"). Thanks in advance for any kind of response you would like to give to my request.
 

oidex

Active Member
Jan 9, 2018
714
1,831
Thank you for the very useful tool, but I was wondering if it would be possible to create a similar one that could instead hook exclusively the text lines related to the choices present in Renpy games (those in the choice menus, to be clear).
Something like this (let's call it a Playthrough Helper or Choice Recorder) would be very useful to me to greatly speed up the task of creating playtroughs to export as text documents or more simply to record, in a similar type of file, the choices made in a given game path (sometimes I've found myself picking up a game I haven't played in a long time and wondering, "How did I get here? What are the choices I made?"). Thanks in advance for any kind of response you would like to give to my request.
I tried something like this
Python:
init python:
    import inspect
    import pygame.scrap

    def to_clipboard(text):
        who = inspect.currentframe().f_back.f_locals.get('who')
        if who is None:
            pygame.scrap.put(pygame.scrap.SCRAP_TEXT, text.encode("utf-8"))

        return text


    config.say_menu_text_filter = to_clipboard
But for some reason that only grabs the last choice.
If it's possible as a /game/.rpy drop-in I don't see how, you'd probably have to grab it in the renpy engine code directly
 
  • Like
Reactions: Dan5k74

Six0

Well-Known Member
Mar 22, 2019
1,019
2,725
Please tell me there's a way to tweak this so that the [Speaker] names aren't copied and only the dialog text is. That's exactly what I've been needing for Text-to-Speech in Ren'py games, since the built in clipboard voicing can't do this.

EDIT: Nevermind, after some trial and error I found the code that works.
Change: line = "[%s] %s" % (d.get("who"), d.get("what"))
to: line = "%s" % (d.get("what"))

THANK YOU FOR THIS SCRIPT!
 
Last edited:

leowolf1993

New Member
Jun 30, 2023
3
0
Hello, I have been using your Python script to retrieve text for translation purposes. However, I have a question: Is it possible to extract options from within a game? Do you have any good methods for this? Thank you very much.
 

Six0

Well-Known Member
Mar 22, 2019
1,019
2,725
Hello, I have been using your Python script to retrieve text for translation purposes. However, I have a question: Is it possible to extract options from within a game? Do you have any good methods for this? Thank you very much.
You can use Ren'Py's built-in Text-to-Clipboard feature for that (Shift+A). Since it copies EVERYTHING to the clipboard instead of just dialog and names.

And while I'm here, this script could really use an on/off switch. It's already the best Ren'Py script in the world, but could be even better. Because the only caveat is when you use skip/fast-forward, it's prone to triggering errors.
 

leowolf1993

New Member
Jun 30, 2023
3
0
You can use Ren'Py's built-in Text-to-Clipboard feature for that (Shift+A). Since it copies EVERYTHING to the clipboard instead of just dialog and names.

And while I'm here, this script could really use an on/off switch. It's already the best Ren'Py script in the world, but could be even better. Because the only caveat is when you use skip/fast-forward, it's prone to triggering errors.
Thanks for the reply, but unfortunately, after I pressed shift+c to turn on the clipboard, I still couldn't copy the menu options to the clipboard ......
Am I doing something wrong? Or do different versions have different behaviors?
 

Six0

Well-Known Member
Mar 22, 2019
1,019
2,725
Thanks for the reply, but unfortunately, after I pressed shift+c to turn on the clipboard, I still couldn't copy the menu options to the clipboard ......
Am I doing something wrong? Or do different versions have different behaviors?
Did you try hovering the mouse over what you want copied? I know whenever I used the built-in text to clipboard, it copied any menu item I mouseovered and that was hella annoying because I use a text-to-speech app. If it's not doing that for you, maybe the menu items aren't text, but images. Since y'know, some Ren'Py devs are pretentious like that.
 

evaboy01

New Member
Mar 12, 2018
2
3
The script doesn't work after version 8.3.0. If possible could we get an update?
我剛剛用gtp修改 最後成功的
I just used gtp to modify it and finally succeeded.

--------------------------------------------------------
init python:
import inspect
import pygame.scrap

def to_clipboard(event, **kwargs):
if event == "begin":
# Get 'who' and 'what' from kwargs
who = kwargs.get('who', None)
# Default to None
what = kwargs.get('what', 'No text')
# Create the line based on whether 'who' is known
if who:
line = "[%s] %s" % (who, what)
else:
line = what # Only show 'what' if 'who' is unknown
pygame.scrap.init() # Initialize pygame scrap
pygame.scrap.put(pygame.scrap.SCRAP_TEXT, line.encode("utf-8")) # Set clipboard content
config.all_character_callbacks.append(to_clipboard)

--------------------------------------------------------

init python:
import inspect
import pygame.scrap

def to_clipboard(event, **kwargs):
if event == "begin":
who = kwargs.get('who', )
what = kwargs.get('what', )
pygame.scrap.init()
pygame.scrap.put(pygame.scrap.SCRAP_TEXT, what.encode("utf-8"))
config.all_character_callbacks.append(to_clipboard)

--------------------------------------------------------
#Can display 2 segments, such as... Apocalypse Lovers
#可以顯示2段文字,像是 ... 天啟戀人

init python:
import inspect
import pygame.scrap

def to_clipboard(event, **kwargs):
if event == "begin":
# Get 'who' and 'what' from kwargs
who = kwargs.get('who', None)
# Default to None
what = kwargs.get('what', 'No text')
# Check if 'what' contains a newline character
if '\n' in what:
# Count the number of paragraphs (split by newline)
paragraphs = what.split('\n')
# If the number of paragraphs is greater than 2 or 100, do not set clipboard
if len(paragraphs) > 2: # Change this number to 100 if needed
return # Do not set clipboard if there are more than 2 paragraphs
# Create the line based on whether 'who' is known
if who:
line = "[%s] %s" % (who, what)
else:
line = what # Only show 'what' if 'who' is unknown
pygame.scrap.init() # Initialize pygame scrap
pygame.scrap.put(pygame.scrap.SCRAP_TEXT, line.encode("utf-8")) # Set clipboard content
config.all_character_callbacks.append(to_clipboard)

--------------------------------------------------------
 
Last edited:

CeciliaM

New Member
Aug 6, 2020
11
18
我剛剛用gtp修改 最後成功的
I just used gtp to modify it and finally succeeded.

--------------------------------------------------------
init python:
import inspect
import pygame.scrap

def to_clipboard(event, **kwargs):
if event == "begin":
# Get 'who' and 'what' from kwargs
who = kwargs.get('who', None)
# Default to None
what = kwargs.get('what', 'No text')
# Create the line based on whether 'who' is known
if who:
line = "[%s] %s" % (who, what)
else:
line = what # Only show 'what' if 'who' is unknown
pygame.scrap.init() # Initialize pygame scrap
pygame.scrap.put(pygame.scrap.SCRAP_TEXT, line.encode("utf-8")) # Set clipboard content
config.all_character_callbacks.append(to_clipboard)

--------------------------------------------------------
thx :)