- 115
- Posts
- 11
- Years
- Seen May 17, 2023
Accessibility script
This script turns text in the game to speech using a text-to-speech program called eSpeak.
Download
Download the demo
Features:
- When first running the game (during title screen), eSpeak is auto-installed.
- You can set the text-to-speech ON/OFF
- you can control the volume, pitch, speed and choose between 5 male voices and 5 female voices.
- Speaks out all text in game, including menu options (yes/no etc)
Compatibility:
wasn't tested in pokemon Essentials.
windows only.
How to install:
I recommend making one version of your game accessible- release your game with and without this script.*
otherwise, you'll have to set it on/off , when starting a new game.
The demo shows how to use an event to set it on/off, change volume, voice, etc.
1) Add this script in a new page above Main:
2) Copy these files from the demo to your game folder:
- eSpeak install file
- espeak.exe
* if you add text asking the player whether to set accessibility ON, blind people won't see it.
You can also turn it on/off using a script : TTS.is_on = true / false
Known bugs:
- sentences may "overlap", when the player spams the A button. you can raise the speed to fix it.
- after installing eSpeak, you must restart the game (being fixed)
This script turns text in the game to speech using a text-to-speech program called eSpeak.
Download
Download the demo
Features:
- When first running the game (during title screen), eSpeak is auto-installed.
- You can set the text-to-speech ON/OFF
- you can control the volume, pitch, speed and choose between 5 male voices and 5 female voices.
- Speaks out all text in game, including menu options (yes/no etc)
Compatibility:
wasn't tested in pokemon Essentials.
windows only.
How to install:
I recommend making one version of your game accessible- release your game with and without this script.*
otherwise, you'll have to set it on/off , when starting a new game.
The demo shows how to use an event to set it on/off, change volume, voice, etc.
1) Add this script in a new page above Main:
Spoiler:
Code:
# ------------------------------------------------------------------- #
# * Text To Speech #
# #
# Instructions #
# #
# - Use a script / script command inside an event to control this. #
# - To set accessibility mode on, use: TTS.is_on = true (line 142) #
# it's on be default, you should make the player set it ON/OFF #
# in the menu/ in the title screen. #
# - To set the volume(0-100), use: #
# TTS.volume = 30 #
# - To set the speed of speech (80-150), use: #
# TTS.speed = 150 #
# - To set the pitch (0-100), use: #
# TTS.pitch = 150 #
# - To set the voice, use: #
# TTS.variant = '+m3' #
# - To add a pause after each sentence, use: #
# TTS.sentence_pause = true #
# (false turns it off) #
# ------------------------------------------------------------------- #
class Game_System
attr_accessor :accessibility_turned_on
alias tts_initialize initialize
def initialize
tts_initialize
@accessibility_turned_on = false
end
end
class Window_Message
alias tts_initialize initialize
def initialize
tts_initialize
@lines = []
end
def multi_line?(str)
return str.count("\n") > 1
end
def join_all_lines(msg)
@lines = msg.split("\n")
for line in @lines
line.delete!("\n", "")
end
all_lines = @lines.join(" ")
return all_lines
end
alias tts_refresh refresh
def refresh
msg = $game_temp.message_text
if TTS.is_on? and msg != nil
if multi_line?(msg)
msg = join_all_lines(msg)
end
$game_temp.tts_need_refresh = TTS.message_playing?
TTS.speak(msg)
end
tts_refresh
end
alias tts_update update
def update
if Graphics.frame_count / Graphics.frame_rate != @total_sec
if $game_temp.tts_need_refresh
@total_sec = Graphics.frame_count / Graphics.frame_rate
TTS.refresh
end
end
TTS.refresh
tts_update
end
end
class Window_Selectable
#alias update, so it speaks the menu option when hovering on them
alias tts_update update
def update
return if @commands.nil?
if @last_index != @index
if @last_index.nil?
@last_index = @index
return
end
if (TTS.is_on?)
TTS.speak(@commands[@index])
#$game_system.bgm_play($data_system.title_bgm)
end
@last_index = @index
end
TTS.refresh
tts_update
end
end
class Window_Command
alias tts_initialize initialize
def initialize(width, commands)
tts_initialize(width, commands)
if (TTS.is_on?)
TTS.speak("Menu options: " + @commands.join(','))
end
end
end
class Scene_Title
alias tts_main main
def main
if (TTS.is_on?)
path = '"' + "C:/Program Files (x86)/eSpeak/TTSApp.exe" + '"'
code = "if not exist " + path + " start /w setup_espeak-1.48.04.exe /s"
system(code)
TTS.speak("Welcome to espeak demo")
end
tts_main
end
end
module TTS
#"C:\Program Files (x86)\eSpeak\command_line\espeak.exe"
TTS_APP = 'espeak.exe'
@@is_on = true
@@message_playing = false
@@pending = []
@@volume = 50 # volume percent. espeak uses 0-200
@@sentence_pause = false # add a pause after each sentence
@@speed = 150 # use values of 80-500
@@pitch = 50
@@gender = 'male'
@@voices = {'male31' =>'+m1', 'male2' =>'+m2', 'male3' =>'+m3', 'male4' =>'+m4',
'male5' =>'+m5', 'female1' => '+f1', 'female2' => '+f2', 'female3' => '+f3',
'female4' => '+f4', 'female5' => '+f5'}
@@variant = @@voices['male3']
module_function
def speak(text)
return if text.nil?
if @@message_playing
@@pending.push(text + '') # don't push a pointer to $game_temp.message_text
return false
end
@@message_playing = true
text = text.delete("\r\n")
if multi_line?(text)
set_multi_line(text)
return true
end
text = '"' + text + '"'
args = [text]
pause = @@sentence_pause ? '-z' : ''
result = system("START /MIN espeak.exe #{pause} -v #{@@variant} -s #{@@speed} -p #{@@pitch} -a #{@@volume*2} #{text}")
@@counter = text.size / 18 # was 14
return true
end
def refresh
unless @@counter.nil? or @@counter == 0
@@counter = @@counter - 1
else
@@message_playing = false
if @@pending.length > 0
text = @@pending.shift
speak(text) unless text.nil?
else
$game_temp.tts_need_refresh = false unless $game_temp.nil?
end
end
end
def is_on?
return @@is_on
end
def multi_line?(str)
return str.count("\n") > 1
end
def set_multi_line(text)
@@curr_msg = text.split('\n')
@@line = 0
refresh
end
def message_playing?
return @@message_playing
end
# voice: use 'male1'..'male5' or 'female1'..'female5'
def voice=(voice)
@@variant = @@voices[voice]
end
# percent: 0-100
def pitch=(percent)
percent = [percent,0].max
percent = [percent,100].min
@@pitch = percent
end
# is_on: true or false
def sentence_pause=(is_on)
@@sentence_pause = is_on
end
# percent: 0-100
def volume=(percent)
percent = [percent,0].max
percent = [percent,100].min
@@volume = percent
end
# percent: 0-100
def speed=(percent)
percent = 5 * percent
percent = [percent,80].max
percent = [percent,500].min
@@speed = percent
end
end
class Game_Temp
attr_accessor :tts_need_refresh
alias tts_initialize initialize
def initialize
tts_initialize
@tts_need_refresh = false
end
end
2) Copy these files from the demo to your game folder:
- eSpeak install file
- espeak.exe
* if you add text asking the player whether to set accessibility ON, blind people won't see it.
You can also turn it on/off using a script : TTS.is_on = true / false
Known bugs:
- sentences may "overlap", when the player spams the A button. you can raise the speed to fix it.
- after installing eSpeak, you must restart the game (being fixed)
Last edited: