現在、PythonでSAPI5を用いてテキスト読み上げを行うときにXMLタグを用いて局所的に音量や音程を変えようとしています。
それをSSMLタグを用いて行いたいのですがやり方がよくわかりませんのでアドバイスいただけたら助かります。
以下に、現在使っているXMLを用いたコードを添付しておきます。
Python
1 # -*- coding: utf-8; -*- 2#Python3.x 3 4 5from win32com.client import constants 6import win32com.client 7import sys 8 9#speech = win32com.client.Dispatch("Speech.SpVoice") 10speech = win32com.client.Dispatch("Sapi.SpVoice") 11SVSFlag = 11 # SVSFIsXML | SVSFlagsAsync | SVSFPurgeBeforeSpeak 12 13 14voiceInfo = speech.GetVoices() 15voices = 20*[''] 16for i in range(voiceInfo.Count): 17 voices[i] = voiceInfo.Item(i).GetAttribute("Name") 18 print ("(" + str(i) + ") " + voices[i]) 19 20while 1: 21 voiceNo = int(input('Voice 0 to ' + str(voiceInfo.Count-1)+ ' : ')) 22 print (voiceInfo.Count) 23 if 0 <= voiceNo and voiceNo < voiceInfo.Count: 24 print (voiceNo) 25 break 26 27 28while 1: 29 volume = int(input('Volume 0 to 100 : ')) 30 if 0 <= volume and volume<= 100: 31 print 32 break 33 34while 1: 35 rate = int(input('Rate -10 to 10 : ')) 36 if -10 <= rate and rate <= 10: 37 break 38 39while 1: 40 pitch = int(input('Pitch -10 to 10 : ')) 41 if -10 <= pitch and pitch <= 10: 42 break 43try: 44 speech.Voice = voiceInfo.Item(voiceNo) 45except: 46 print ("fail to set property (by assign)") 47 try: 48 speech.SetVoice(voiceInfo.Item(voiceNo)) 49 except: 50 print ("fail to set property (by SetXXX)") 51speech.Volume = volume 52speech.Rate = rate 53 54while 1: 55 str = input("Input : ") 56 if len(str)==0: 57 sys.exit() 58 print (str) 59 str = str.replace("<","<") 60 str = str.replace("[","<rate absspeed=\"4\">") 61 str = str.replace("]","</rate>") 62 str = "<pitch absmiddle=\"%s\">%s</pitch>"%(pitch,str) 63 speech.Speak(str,SVSFlag) 64
あなたの回答
tips
プレビュー