質問編集履歴

3

encoding

2020/06/03 06:03

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -105,3 +105,75 @@
105
105
 
106
106
 
107
107
  ![![イメージ説明](a185e74fa536ba799e2ff6b4b69e8aa4.png)](7d0fb05f0d0a945667718acfbe227d67.png)
108
+
109
+
110
+
111
+ ```
112
+
113
+ from gtts import gTTS
114
+
115
+ import os
116
+
117
+ import tkinter as tk
118
+
119
+ from playsound import playsound
120
+
121
+ from tkinter import filedialog
122
+
123
+
124
+
125
+ win = tk.Tk()
126
+
127
+
128
+
129
+ def chooseFile():
130
+
131
+ global content
132
+
133
+ file = filedialog.askopenfile(filetypes =[('Text Files','*.txt')])
134
+
135
+ sFile = tk.Label(win,text=f"Selected File : {file.name}")
136
+
137
+ sFile.grid(row=1, column=0, columnspan=2)
138
+
139
+ if file is not None:
140
+
141
+ content = file.read()
142
+
143
+ return content
144
+
145
+
146
+
147
+ def convert():
148
+
149
+ text = content
150
+
151
+ speech = gTTS(text=content, lang="ja")
152
+
153
+ speech.save(r'C:\Users\detec\Desktop\speech.mp3', encoding="shift-jis")
154
+
155
+ playsound(r'C:\Users\detec\Desktop\speech.mp3', encoding="shift-jis")
156
+
157
+
158
+
159
+ label = tk.Label(win,text="Select File")
160
+
161
+ label.grid(row=0, column=0, padx=8, pady=8)
162
+
163
+
164
+
165
+ button = tk.Button(win,text="Choose!!",command=chooseFile)
166
+
167
+ button.grid(row=0,column=1,padx=8,pady=8)
168
+
169
+
170
+
171
+ button2 = tk.Button(win,text="Convert", command=convert)
172
+
173
+ button.grid(row=2,column=1,columnspan=2,padx=8,pady=8)
174
+
175
+
176
+
177
+ win.mainloop()
178
+
179
+ ```

2

画像追加

2020/06/03 06:03

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -101,3 +101,7 @@
101
101
  UnicodeDecodeError: 'cp932' codec can't decode byte 0x81 in position 10: illegal multibyte sequence
102
102
 
103
103
  ```
104
+
105
+
106
+
107
+ ![![イメージ説明](a185e74fa536ba799e2ff6b4b69e8aa4.png)](7d0fb05f0d0a945667718acfbe227d67.png)

1

エラーの追加

2020/06/03 04:58

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -79,3 +79,25 @@
79
79
 
80
80
 
81
81
  どこに入れれば読み取ってくれますか??
82
+
83
+
84
+
85
+
86
+
87
+ エラー全文です
88
+
89
+ ```
90
+
91
+ Traceback (most recent call last):
92
+
93
+ File "C:\Users\detec\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
94
+
95
+ return self.func(*args)
96
+
97
+ File "audio.py", line 15, in chooseFile
98
+
99
+ content = file.read()
100
+
101
+ UnicodeDecodeError: 'cp932' codec can't decode byte 0x81 in position 10: illegal multibyte sequence
102
+
103
+ ```