Пример #1
0
def _jtalk_speak(msg, index=None, prop=None):
	global currIndex, buff
	global currentEngine
	global lastIndex
	if prop is None: return
	currIndex = index
	if prop.characterMode:
		fperiod_current = voice_args['fperiod']
	else:
		fperiod_current = fperiod
	msg = unicode_normalize(msg)
	msg = jtalkPrepare.convert(msg)
	lw = None
	if DEBUG: lw = logwrite
	setSpeaking(True)
	currentEngine = 2
	if DEBUG: logwrite("p:%d i:%d msg:%s" % (prop.pitch, prop.inflection, msg))
	level =	int(max_level * speaker_attenuation)
	la = 0.020 * (prop.inflection + voice_args.get('inflection_bias', 0)) # 50 = original range
	ls = 0.015 * (prop.pitch - 50.0 + voice_args['pitch_bias']) # 50 = no shift
	lo = ls + voice_args['lf0_base'] * (1 - la)
	if DEBUG: logwrite("lo:%f la:%f" % (lo, la))
	lastIndex = currIndex
	currIndex = None
	for t in string.split(msg):
		if DEBUG: logwrite("unicode (%s)" % t)
		s = text2mecab(t)
		if DEBUG: logwrite("utf-8 (%s)" % s.decode('utf-8', 'ignore'))
		if not isSpeaking(): libjt_refresh(); return
		mf = MecabFeatures()
		Mecab_analysis(s, mf, logwrite_=logwrite)
		if DEBUG: Mecab_print(mf, logwrite)
		Mecab_correctFeatures(mf)
		if DEBUG: Mecab_print(mf, logwrite)
		ar = Mecab_splitFeatures(mf, CODE_='utf-8')
		for a in ar:
			if isSpeaking():
				if DEBUG: Mecab_print(a, logwrite, CODE_='utf-8')
				Mecab_utf8_to_cp932(a)
				if DEBUG: logwrite("Mecab_analysis done")
				libjt_synthesis(
					a.feature,
					a.size,
					fperiod_ = fperiod_current,
					feed_func_ = player.feed, # player.feed() is called inside
					is_speaking_func_ = isSpeaking,
					begin_thres_ = thres_level,
					end_thres_ = thres2_level,
					level_ = level,
					logwrite_ = lw,
					lf0_offset_ = lo,
					lf0_amp_ = la)
				libjt_refresh()
				if DEBUG: logwrite("libjt_synthesis done")
			del a
		del mf
	player.idle()
	setSpeaking(False)
	currentEngine = 0
Пример #2
0
def runTasks():
    jtalkPrepare.setup()
    count = 0
    for item in tests:
        msg = item[0]
        msg = unicode_normalize(msg)
        s = jtalkPrepare.convert(msg)
        if item[1] != s:
            _print("expected:%s result:%s" % (item[1], s))
            count += 1
    return count
Пример #3
0
def runTasks():
	jtalkPrepare.setup()
	count = 0
	for item in tests:
		msg = item[0]
		normalized = unicode_normalize(msg)
		s = jtalkPrepare.convert(normalized)
		if item[1] != s:
			_print('input:%s normalized:%s result:%s expected:%s' % (msg, normalized, s, item[1]))
			count += 1
	return count
Пример #4
0
def do_synthesis(msg, voice_args, do_play, do_write, do_log, fperiod, pitch=50, inflection=50, vol=50):
	global count
	msg = jtalkPrepare.convert(msg)
	s = text2mecab(msg)
	__print("utf-8: (%s)" % s.decode('utf-8', 'ignore'))
	mf = MecabFeatures()
	Mecab_analysis(s, mf)
	Mecab_print(mf, __print)
	Mecab_correctFeatures(mf)
	ar = [mf] #ar = Mecab_splitFeatures(mf)
	__print('array size %d' % len(ar))
	max_level = int(326.67 * int(vol) + 100) # 100..32767
	level =	int(max_level * voice_args['speaker_attenuation'])
	lf0_amp = 0.020 * inflection # 50 = original range
	ls = 0.015 * (pitch - 50.0 + voice_args['pitch_bias']) # 50 = no shift
	lf0_offset = ls + voice_args['lf0_base'] * (1 - lf0_amp)
	for a in ar:
		count += 1
		__print('feature size %d' % a.size)
		Mecab_print(a, __print)
		Mecab_utf8_to_cp932(a)
		if do_write:
			w = "_test%d.jt.wav" % count
		else:
			w = None
		if do_log:
			l = "_test%d.jtlog" % count
		else:
			l = None
		data = libjt_synthesis(a.feature,
							   a.size,
							   begin_thres_=32,
							   end_thres_=32,
							   level_=level,
							   fperiod_ = fperiod,
							   lf0_offset_ = lf0_offset,
							   lf0_amp_ = lf0_amp,
							   logwrite_ = __print,
							   jtlogfile_ = l,
							   jtwavfile_ = w)
		if data:
			__print('data size %d' % len(data))
			if do_play:
				pa_play(data, samp_rate = voice_args['samp_rate'])
			if do_write:
				w = wave.Wave_write("_test%d.wav" % count)
				w.setparams( (1, 2, voice_args['samp_rate'], len(data)/2,
							  'NONE', 'not compressed') )
				w.writeframes(data)
				w.close()
		libjt_refresh()
		del a
	del mf
Пример #5
0
def do_synthesis(msg, voice_args, do_play, do_write, do_write_jt, do_log, fperiod, pitch=50, inflection=50, vol=50):
	msg = jtalkPrepare.convert(msg)
	s = text2mecab(msg)
	__print("utf-8: (%s)" % s.decode('utf-8', 'ignore'))
	mf = MecabFeatures()
	Mecab_analysis(s, mf)
	Mecab_print(mf, __print)
	Mecab_correctFeatures(mf)
	ar = Mecab_splitFeatures(mf)
	__print('array size %d' % len(ar))
	max_level = int(326.67 * int(vol) + 100) # 100..32767
	level =	int(max_level * voice_args['speaker_attenuation'])
	lf0_amp = 0.020 * inflection # 50 = original range
	ls = 0.015 * (pitch - 50.0 + voice_args['pitch_bias']) # 50 = no shift
	lf0_offset = ls + voice_args['lf0_base'] * (1 - lf0_amp)
	count = 0
	for a in ar:
		count += 1
		__print('feature size %d' % a.size)
		Mecab_print(a, __print)
		Mecab_utf8_to_cp932(a)
		if do_write_jt:
			w = "_test%d.jt.wav" % count
		else:
			w = None
		if do_log:
			l = "_test%d.jtlog" % count
		else:
			l = None
		data = libjt_synthesis(a.feature,
							   a.size,
							   begin_thres_=32,
							   end_thres_=32,
							   level_=level,
							   fperiod_ = fperiod,
							   lf0_offset_ = lf0_offset,
							   lf0_amp_ = lf0_amp,
							   logwrite_ = __print,
							   jtlogfile_ = l,
							   jtwavfile_ = w)
		if data:
			__print('data size %d' % len(data))
			if do_play:
				pa_play(data, samp_rate = voice_args['samp_rate'])
			if do_write:
				w = wave.Wave_write("_test%d.wav" % count)
				w.setparams( (1, 2, voice_args['samp_rate'], len(data)/2,
							  'NONE', 'not compressed') )
				w.writeframes(data)
				w.close()
		libjt_refresh()
		del a
	del mf