Renpy won't load python script

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
User avatar
Logically Anime
Newbie
Posts: 7
Joined: Fri May 11, 2018 7:44 pm
Contact:

Renpy won't load python script

#1 Post by Logically Anime » Thu Nov 22, 2018 10:13 pm

Hi there, I'm having problems with getting renpy work with this script https://github.com/alexram1313/text-to-speech-sample
When I implement it call it using

Code: Select all

import TextToSpeech
I get this error.

Code: Select all

While running game code:
  File "game/script-ch1.rpy", line 19, in script
    init python:
  File "game/script-ch1.rpy", line 20, in <module>
    import TextToSpeech
SyntaxError: invalid syntax (python-packages/TextToSpeech.py, line 12)
Thank you for your time.

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

Re: Renpy won't load python script

#2 Post by Imperf3kt » Fri Nov 23, 2018 12:13 am

From what I can tell (I'm a novice in Python) it looks like there's an error in the file TextToSpeech.py in line 12.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Free Android GUI - Updated occasionally

User avatar
Logically Anime
Newbie
Posts: 7
Joined: Fri May 11, 2018 7:44 pm
Contact:

Re: Renpy won't load python script

#3 Post by Logically Anime » Fri Nov 23, 2018 2:30 am

Imperf3kt wrote:
Fri Nov 23, 2018 12:13 am
From what I can tell (I'm a novice in Python) it looks like there's an error in the file TextToSpeech.py in line 12.
The thing is it runs perfectly through actual python...

User avatar
Remix
Eileen-Class Veteran
Posts: 1441
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: Renpy won't load python script

#4 Post by Remix » Fri Nov 23, 2018 1:34 pm

param:type=default is not valid syntax for Python 2.7 (typing only started in Python 3.5)

You will need to recode those parts of the file to make it work in Ren'Py (basically alter all the words_pron_dict:str bits ... there might be more errors further though)
Frameworks & Scriptlets:

User avatar
Logically Anime
Newbie
Posts: 7
Joined: Fri May 11, 2018 7:44 pm
Contact:

Re: Renpy won't load python script

#5 Post by Logically Anime » Sat Nov 24, 2018 1:07 am

Remix wrote:
Fri Nov 23, 2018 1:34 pm
param:type=default is not valid syntax for Python 2.7 (typing only started in Python 3.5)

You will need to recode those parts of the file to make it work in Ren'Py (basically alter all the words_pron_dict:str bits ... there might be more errors further though)
Hah you were right. There were more errors. It imports it now, but I'm getting this error :?

Code: Select all

While running game code:
  File "game/script-ch1.rpy", line 19, in script
    init python:
  File "game/script-ch1.rpy", line 21, in <module>
    TextToSpeech.get_pronunciation("buy")
AttributeError: 'module' object has no attribute 'get_pronunciation'

User avatar
trooper6
Lemma-Class Veteran
Posts: 3706
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Renpy won't load python script

#6 Post by trooper6 » Sat Nov 24, 2018 2:12 am

by the way, do you know that Renpy has a build in text to speech function?
https://www.renpy.org/doc/html/self_voicing.html
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Logically Anime
Newbie
Posts: 7
Joined: Fri May 11, 2018 7:44 pm
Contact:

Re: Renpy won't load python script

#7 Post by Logically Anime » Sat Nov 24, 2018 2:24 am

trooper6 wrote:
Sat Nov 24, 2018 2:12 am
by the way, do you know that Renpy has a build in text to speech function?
https://www.renpy.org/doc/html/self_voicing.html
I do know this but i need a custom voice not the ms sam voice

User avatar
Remix
Eileen-Class Veteran
Posts: 1441
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: Renpy won't load python script

#8 Post by Remix » Sat Nov 24, 2018 7:46 am

You'd need to post your modified load.py so anyone helping can view why it isn't working...
Frameworks & Scriptlets:

User avatar
Logically Anime
Newbie
Posts: 7
Joined: Fri May 11, 2018 7:44 pm
Contact:

Re: Renpy won't load python script

#9 Post by Logically Anime » Sat Nov 24, 2018 5:07 pm

Remix wrote:
Sat Nov 24, 2018 7:46 am
You'd need to post your modified load.py so anyone helping can view why it isn't working...
Of course, I didnt really change that much from the original however.

Code: Select all

import re
import wave
import pyaudio
import thread
import time
from pydub import AudioSegment

class TextToSpeech:
	
	CHUNK = 1024
	
	def __init__(self, words_pron_dict = 'cmudict-0.7b.txt'):
		self._l = {}
		self._load_words(words_pron_dict)
	
	def _load_words(self, words_pron_dict):
		print("Loading dictionary...")
		with open(words_pron_dict, 'r') as file:
			for line in file:
				if not line.startswith(';;;'):
					key, val = line.split('  ',2)
					self._l[key] = re.findall(r"[A-Z]+",val)
	
	def get_pronunciation(self, str_input):
		list_pron = []
		for word in re.findall(r"[\w']+",str_input.upper()):
			if word in self._l:
				list_pron += self._l[word]
			else:
				list_pron += ["umm"]
			list_pron += ['0']
		print(list_pron)
		output_sound = AudioSegment.from_wav("sounds/0.wav")
		for pron in list_pron:
			output_sound += AudioSegment.from_wav("sounds/"+pron+".wav")
		output_sound.export("output.wav", format="wav")
	
		try:
			wf = wave.open("output.wav", 'rb')
			p = pyaudio.PyAudio()
			stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
				channels=wf.getnchannels(),
				rate=wf.getframerate(),
				output=True)
			
			data = wf.readframes(TextToSpeech.CHUNK)
			
			while data:
				stream.write(data)
				data = wf.readframes(TextToSpeech.CHUNK)
			
			stream.stop_stream()
			stream.close()
			
			p.terminate()
		except:
			pass




if __name__ == '__main__':
	tts = TextToSpeech()
	tts.get_pronunciation('Enter a word or phrase')
	while True:
		tts.get_pronunciation(input('Enter a word or phrase: '))

Post Reply

Who is online

Users browsing this forum: deadhand, Google [Bot], RicharDann