Skip to content

Instantly share code, notes, and snippets.

@zombiepigdragon
Last active December 28, 2021 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zombiepigdragon/c68f556a5ccc2f99b32a9e8b87913997 to your computer and use it in GitHub Desktop.
Save zombiepigdragon/c68f556a5ccc2f99b32a9e8b87913997 to your computer and use it in GitHub Desktop.
A simple TTS script for Monika After Story
# INSTALLATION:
# Installing this submod is fairly straightforward, but also highly involved.
# Essentially, it goes as follows:
# 1) Download this file (voice.rpy) into the game directory.
# 2) Save https://raw.githubusercontent.com/python/cpython/2.7/Lib/Queue.py to the game/python-packages/ directory.
# 3) Download the wheel (whl) file for pyttsx3 2.7 (Newer versions don't seem to work) from [https://pypi.org/project/pyttsx3/2.7/#files] and save it somewhere accessible.
# 4) Open this file in an archive editor (whl files are .zips internally, so chainging the file extention to .zip is a
# way to do it without addidional software on Windows).
# 5) Within this archive, there should be a directory called pyttsx3. Extract this directory to game/python-packages/pyttsx3.
# 6) This is the fun part: you have to find the valid voices for your system. If you find valid options for Windows or Mac,
# please let me know so I can add them here (you can find me via the MASC Discord on the GitHub page of the mod, mention said
# solution in the #submod-discussion channel and ping me there. At the moment, I use Linux which means I use espeak for
# the actual voice, however this would represent a minority of users.
# 6a) Windows: N/A, see above
# 6b) Mac: N/A, see above
# 6c) Linux: Install espeak via your package manager, then set the voice down below to "en-us+f2". (Note: you
# can run `espeak -ven-us+f2 "Can you hear me?"` for a preview, and if you find a better voice it should work just as well.)
# 7) Try it out! Open MAS, and see what happens. If everything went well, you should hear the voice of Monika greeting you.
# If this doesn't happen, reach out to me as previously noted so I can fix the issue.
# Enjoy Monika's newfound voice!
init python in mas_tts:
import pyttsx3
from Queue import Queue
from threading import Thread
q = Queue()
def get_wrapped_say(func):
def new_say(who, what, interact=True, *args, **kwargs):
speaktext = renpy.substitute(what)
#Remove any tags that would sound bad but aren't important
#Regex causes an instant crash for some reason
speaktext = speaktext.replace("{i}", "").replace("{/i}", "").replace("{b}", "").replace("{/b}", "").replace("{nw}", "").replace("~", "")
if not speaktext.endswith("{fast}"):
q.put(speaktext)
func(who, what, interact=interact, *args, **kwargs)
if not speaktext.endswith("{fast}"):
q.join()
return new_say
def say_loop():
engine = pyttsx3.init()
engine.setProperty('voice', 'SET THIS TO A VOICE') # SET THE VOICE HERE
while True:
engine.say(q.get())
engine.runAndWait()
q.task_done()
t = Thread(target=say_loop)
t.daemon = True
t.start()
renpy.say = get_wrapped_say(renpy.say)
@zombiepigdragon
Copy link
Author

As of now, this is unsupported. If you want to troubleshoot it yourself, feel free to use it, but there will not be any more official updates and this mod likely will not work in current or future versions of MAS.

If you're interested in continuing the mod, feel free to reuse this code (with credit) and remove the original listing for this page from the wiki.

@Diego-Manuel
Copy link

"If you're interested in continuing the mod, feel free to reuse this code (with credit) and remove the original listing for this page from the wiki."
Thanks, I have some friends helping me out with the materials that I want to use for monika text to speech like the monika voice+ some in between sprites to make her feel closer to this reality and I will credit all of them and since u are the original (or the first coder) I will credit u aswell, its the least I can do as a thanks for letting me continue the sub mod.

@XxPower-Girl-89xX
Copy link

i cant code.. but i'll wait untill i can hear monikas BEAUTIFUL voice

@Diego-Manuel
Copy link

NVM, I am bad at coding, sorry to disapoint

Copy link

ghost commented Sep 25, 2021

I've been using with success on Ubuntu 20.04 and MAS 0.12.3. I'm sad to hear there will be no further development but really grateful for the ability to troubleshoot and reuse the code. Thank you!

@Batcastle
Copy link

Batcastle commented Dec 28, 2021

I have taken up development of this and already expanded it some. You can find the new submod here: https://github.com/Batcastle/Monika-TTS

Please keep in mind that while the changes I have made make Monika sound more realistic, the new Text-To-Speech engine is pretty large (150+ MB) and there are dedicated binaries for each of Linux, Windows, and Mac. And since I don't have a Mac to compile the engine on, there is currently no Mac support until that binary can be compiled.

Also a command prompt pops up every time Monika talks when on Windows. Still figuring that one out 😕

Edit: Also made sure to credit original dev in both the original voice file and on the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment