Exemplo n.º 1
0
	def __init__(self,tagid,text,basename,audiodir):
		"""
			constructor for class Audio

			@param integer tagid => tag id for the audio
			@param string text => text representation of the audio
			@param string basename => basename to be used in filename generation
			@param string audiodir => full path to the directory where the audio file is located
			@return object Audio

			the constructor will only set values for class member variables tagid and text
			values for the remaing class member variables are set during generation of ogg audio
		"""
		self.tagid = tagid
		self.text = text
		# generate filenames for wav audio and ogg audio
		self.wavfile = messagehelper.genfilename(text, basename, audiodir, 'wav')
		self.oggfile = messagehelper.genfilename(text, basename, audiodir, 'ogg')
Exemplo n.º 2
0
    def resample(self, destination, voice):
        """
			invokes operation resample() for its audioclip
			and returns False if operation failed, otherwise True

			@param destination => path to destination folder
			@param boolean/string voice => generate missing audio files using this espeak voice
		"""

        # create tags from key string
        i = 0
        tags = []
        key = messagehelper.stripparamtype(self.key)
        param = re.compile("\{\w+\}")
        m = param.search(key)
        while m != None:
            if m.start != 0:
                text = key[0 : m.start()].lstrip(" ").rstrip(" ")
                if len(text) > 0:
                    tags.append((i, text))
                    i += 1
            key = key[m.end() :].lstrip(" ").rstrip(" ")
            m = param.search(key)
        if len(key) > 0:
            tags.append((i, key))

        if len(tags) > 1 and len(self.audioclips) > 1:
            sys.stderr.write("Error: key or translation can contain ONLY one tag\n")
            sys.stderr.write('       key is: "' + self.key + '"\n')
            sys.stderr.write('       translation is: "' + self.text + '"\n')
            return False

        result = True
        tag = tags[0]
        audioclip = self.audioclips[0]
        filename = messagehelper.genfilename(tag[1], None, destination, "wav")
        retval = audioclip.resample(filename, voice)
        if retval != True:
            sys.stderr.write(str(retval))
            result = False
        return result