前提・実現したいこと
合成音声エンジンを用いてコマンドプロンプトに入力された文字を読み上げるプログラムをPythonを用いて作成中です。
使用できる音声エンジンを表示し、使用する音声エンジン・音量・ピッチ・スピードを入力した後に読み上げる文章を打ち込む形となっています。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "test.py", line 43, in <module> speech.Voice = voiceInfo.Item(voiceNo) File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 565, in __setattr__ self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value) pywintypes.com_error: (-2147352573, '\x83\x81\x83\x93\x83o\x81[\x82\xaa\x8c\xa9\x82\xc2\x82\xa9\x82\xe8\x82\xdc\x82\xb9\x82\xf1\x81B', None, None)
該当のソースコード
Python
1# -*- coding: utf-8; -*- 2 3from win32com.client import constants 4import win32com.client 5import sys 6 7#speech = win32com.client.Dispatch("Speech.SpVoice") 8speech = win32com.client.Dispatch("Sapi.SpVoice") 9SVSFlag = 11 # SVSFIsXML | SVSFlagsAsync | SVSFPurgeBeforeSpeak 10 11 12voiceInfo = speech.GetVoices() 13voices = 20*[''] 14for i in range(voiceInfo.Count): 15 voices[i] = voiceInfo.Item(i).GetAttribute("Name") 16 print "(" + str(i) + ") " + voices[i] 17 18while 1: 19 voiceNo = int(raw_input('Voice 0 to ' + str(voiceInfo.Count-1)+ ' : ')) 20 print voiceInfo.Count 21 if 0 <= voiceNo and voiceNo < voiceInfo.Count: 22 print voiceNo 23 break 24 25 26while 1: 27 volume = int(raw_input('Volume 0 to 100 : ')) 28 if 0 <= volume and volume<= 100: 29 print 30 break 31 32while 1: 33 rate = int(raw_input('Rate -10 to 10 : ')) 34 if -10 <= rate and rate <= 10: 35 print 36 break 37 38while 1: 39 pitch = int(raw_input('Pitch -10 to 10 : ')) 40 if -10 <= pitch and pitch <= 10: 41 print 42 break 43 44speech.Voice = voiceInfo.Item(voiceNo) #43行目 45speech.Volume = volume 46speech.Rate = rate 47 48while 1: 49 str = raw_input("Input : ") 50 if len(str)==0: 51 sys.exit() 52 print str 53 str = str.replace("<","<") 54 str = "<pitch absmiddle=\"%s\">%s</pitch>"%(pitch,str) 55 speech.Speak(str,SVSFlag) 56 57
試したこと
43行目をコメントアウトし実行するとデフォルトの合成音声エンジンが使用され、正常に動きます。
回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2018/05/06 03:51
2018/05/06 03:58