test2.hsp

sample\hspvoicevox\test2.hsp » Plain Format

;
;	HSPVOICEVOXプラグインによる音声読み上げ
;
#use hspvoicevox,hspinet
#vatstr vvmetas

	;	voicevoxの初期化
	voicevoxinit : res=stat
	if res : dialog "voicevoxの初期化に失敗しました。終了します。("+stat+")" : end

	mes "話す人を選択してください"
	voicevoxgetmetas metas
	;mesbox metas,640,200,0

	sdim idlist,$4000
	sdim utf8js,$8000
	dim idnum,64
	nkfcnv utf8js,metas,"w"

	jptr=0
	jsonopen jptr,utf8js
	jsonnext jptr,jptr,2
	idmax=0
	repeat
		if jptr=0 : break
		jsongets nameu8,"name",jptr
		nkfcnv name,nameu8
		jsongetobj jstyle,"styles",jptr
		jsonnext jstyle,jstyle,2
		repeat
			if jstyle=0 : break
			jsongets nameu8,"name",jstyle
			nkfcnv name2,nameu8
			idlist+=""+name+":"+name2+"\n"
			jsongeti i,"id",jstyle
			idnum(idmax)=i:idmax++
			jsonnext jstyle,jstyle,0
		loop
		jsonnext jptr,jptr,0
	loop

	jsonclose

	selid=0
	objsize 640,24
	listbox selid,200,idlist
	button "Select",*select
	stop

*select
	cls
	mes "準備をしています"
	id=idnum(selid)
	voicevoxload id
	if stat : goto *vverror

	sdim myword,128
	myword = "こんにちは、いい天気ですね。"

*goinput
	cls
	objsize 640,24
	input myword
	button "Speak",*gospeak
	stop

*gospeak
	cls
	mes "再生を開始します"
	voicevoxspeak myword, id, 0
	if stat : goto *vverror

	goto *goinput

*vverror
	errstr=""
	voicevoxgeterror errstr
	dialog "voicevoxの呼び出しに失敗しました。終了します。\n("+errstr+")"
	end