質問編集履歴
2
ご指摘を受けてコードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -102,6 +102,131 @@
|
|
102
102
|
client.run("discordtoken")
|
103
103
|
```
|
104
104
|
|
105
|
+
### voice_generatorのコード
|
106
|
+
|
107
|
+
```
|
108
|
+
import subprocess
|
109
|
+
import re
|
110
|
+
|
111
|
+
# ************************************************
|
112
|
+
# remove_custom_emoji
|
113
|
+
# 絵文字IDは読み上げない
|
114
|
+
# ************************************************
|
115
|
+
def remove_custom_emoji(text):
|
116
|
+
|
117
|
+
#pattern = r'<:[a-zA-Z0-9_]+:[0-9]+>' # カスタム絵文字のパターン
|
118
|
+
pattern = r'<:' # カスタム絵文字のパターン
|
119
|
+
text = re.sub(pattern,'',text) # 置換処理
|
120
|
+
pattern = r':[0-9]+>' # カスタム絵文字のパターン
|
121
|
+
return re.sub(pattern,'',text) # 置換処理
|
122
|
+
|
123
|
+
# ************************************************
|
124
|
+
# url_shouryaku
|
125
|
+
# URLなら省略
|
126
|
+
# ************************************************
|
127
|
+
def url_shouryaku(text):
|
128
|
+
pattern = "https?://[\w/:%#$&?()~.=+\-]+"
|
129
|
+
return re.sub(pattern,'URLは省略するのデス!',text) # 置換処理
|
130
|
+
|
131
|
+
# ************************************************
|
132
|
+
# remove_picture
|
133
|
+
# 画像ファイルなら読み上げない
|
134
|
+
# ************************************************
|
135
|
+
def remove_picture(text):
|
136
|
+
pattern = r'.*(.jpg|.jpeg|.gif|.png|.bmp)'
|
137
|
+
return re.sub(pattern,'',text) # 置換処理
|
138
|
+
|
139
|
+
# ************************************************
|
140
|
+
# remove_command
|
141
|
+
# コマンドは読み上げない
|
142
|
+
# ************************************************
|
143
|
+
def remove_command(text):
|
144
|
+
pattern = r'^\!.*'
|
145
|
+
return re.sub(pattern,'',text) # 置換処理
|
146
|
+
|
147
|
+
# ************************************************
|
148
|
+
# remove_log
|
149
|
+
# 参加ログは読み上げない
|
150
|
+
# ************************************************
|
151
|
+
def remove_log(text):
|
152
|
+
pattern = r'(\【VC参加ログ\】.*)'
|
153
|
+
return re.sub(pattern,'',text) # 置換処理
|
154
|
+
|
155
|
+
# ************************************************
|
156
|
+
# user_custam
|
157
|
+
# ユーザ登録した文字を読み替える
|
158
|
+
# ************************************************
|
159
|
+
def user_custam(text):
|
160
|
+
|
161
|
+
f = open('C:/open_jtalk/bin/dic.txt', 'r')
|
162
|
+
line = f.readline()
|
163
|
+
|
164
|
+
while line:
|
165
|
+
pattern = line.strip().split(',')
|
166
|
+
if pattern[0] in text:
|
167
|
+
text = text.replace(pattern[0], pattern[1])
|
168
|
+
print('置換後のtext:'+text)
|
169
|
+
break
|
170
|
+
else:
|
171
|
+
line = f.readline()
|
172
|
+
f.close()
|
173
|
+
|
174
|
+
return text
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
# ************************************************
|
179
|
+
# creat_WAV
|
180
|
+
# message.contentをテキストファイルと音声ファイルに書き込む
|
181
|
+
# 引数:inputText
|
182
|
+
# 書き込みファイル:input.txt、output.wav
|
183
|
+
# ************************************************
|
184
|
+
def creat_WAV(inputText):
|
185
|
+
# message.contentをテキストファイルに書き込み
|
186
|
+
|
187
|
+
inputText = remove_custom_emoji(inputText) # 絵文字IDは読み上げない
|
188
|
+
inputText = remove_command(inputText) # コマンドは読み上げない
|
189
|
+
inputText = url_shouryaku(inputText) # URLなら省略
|
190
|
+
inputText = remove_picture(inputText) # 画像なら読み上げない
|
191
|
+
inputText = remove_log(inputText) # 参加ログなら読み上げない
|
192
|
+
inputText = user_custam(inputText) # ユーザ登録した文字を読み替える
|
193
|
+
input_file = 'input.txt'
|
194
|
+
|
195
|
+
with open(input_file,'w',encoding='shift_jis') as file:
|
196
|
+
file.write(inputText)
|
197
|
+
|
198
|
+
command = 'C:/open_jtalk/bin/open_jtalk -x {x} -m {m} -r {r} -ow {ow} {input_file}'
|
199
|
+
|
200
|
+
#辞書のPath
|
201
|
+
x = 'C:/open_jtalk/bin/dic'
|
202
|
+
|
203
|
+
#ボイスファイルのPath
|
204
|
+
#m = 'C:/open_jtalk/bin/nitech_jp_atr503_m001.htsvoice'
|
205
|
+
#m = 'C:/open_jtalk/bin/mei/mei_sad.htsvoice'
|
206
|
+
#m = 'C:/open_jtalk/bin/mei/mei_angry.htsvoice'
|
207
|
+
m = 'C:/open_jtalk/bin/mei/mei_bashful.htsvoice'
|
208
|
+
#m = 'C:/open_jtalk/bin/mei/mei_happy.htsvoice'
|
209
|
+
#m = 'C:/open_jtalk/bin/mei/mei_normal.htsvoice'
|
210
|
+
|
211
|
+
#発声のスピード
|
212
|
+
#r = '2.0'
|
213
|
+
r = '1.2'
|
214
|
+
|
215
|
+
#出力ファイル名 and Path
|
216
|
+
ow = 'output.wav'
|
217
|
+
|
218
|
+
args= {'x':x, 'm':m, 'r':r, 'ow':ow, 'input_file':input_file}
|
219
|
+
|
220
|
+
cmd= command.format(**args)
|
221
|
+
print(cmd)
|
222
|
+
|
223
|
+
subprocess.run(cmd)
|
224
|
+
return True
|
225
|
+
|
226
|
+
if __name__ == '__main__':
|
227
|
+
creat_WAV('テスト')
|
228
|
+
```
|
229
|
+
|
105
230
|
### 補足情報(FW/ツールのバージョンなど)
|
106
231
|
|
107
232
|
PythonバージョンはPython 3.9.0です
|
1
誤字修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
ここに質問の内容を詳しく書いてください。
|
4
3
|
discord.pyで単語登録機能などを備えた簡易的な読み上げBotを作成しています
|
5
4
|
単語登録機能を実装中に以下のエラーメッセージが発生しました。
|
6
5
|
|
@@ -106,4 +105,6 @@
|
|
106
105
|
### 補足情報(FW/ツールのバージョンなど)
|
107
106
|
|
108
107
|
PythonバージョンはPython 3.9.0です
|
109
|
-
Open JTalkで読み上げさせています。
|
108
|
+
Open JTalkで読み上げさせています。
|
109
|
+
また、辞書登録をせずに辞書登録先テキストファイルを削除すれば
|
110
|
+
読み上げは正常に動作します
|