Last active
December 28, 2021 04:33
-
-
Save zombiepigdragon/c68f556a5ccc2f99b32a9e8b87913997 to your computer and use it in GitHub Desktop.
A simple TTS script for Monika After Story
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
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
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!