OzoneAsai commited on
Commit
9180f22
·
verified ·
1 Parent(s): 7a33557

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -75
app.py CHANGED
@@ -1,7 +1,7 @@
1
  from flask import Flask, render_template, request, redirect, url_for, jsonify
2
  from gtts import gTTS
3
  import os
4
- from translation_data import *
5
  app = Flask(__name__)
6
 
7
  # 音声ファイルの保存ディレクトリ
@@ -25,36 +25,7 @@ def generate_audio(text, set_name, index):
25
  tts.save(filename)
26
  return filename
27
 
28
- # whereAudio エンドポイントを作成して音声ファイルのURLを返す
29
- @app.route('/whereAudio')
30
- def where_audio():
31
- set_name = request.args.get('set', 'A')
32
- index = int(request.args.get('index', 0))
33
-
34
- if set_name == 'A':
35
- english = english_sentences_A[index]
36
- elif set_name == 'B':
37
- english = english_sentences_B[index]
38
- elif set_name == 'C':
39
- english = english_sentences_C[index]
40
- elif set_name == 'D':
41
- english = english_sentences_D[index]
42
- elif set_name == 'F':
43
- english = english_sentences_F[index]
44
- elif set_name == 'G':
45
- english = english_sentences_G[index]
46
-
47
- # 音声ファイルの生成
48
- audio_url = url_for('static', filename=f"audio/{set_name}_{index}.mp3")
49
- generate_audio(english, set_name, index)
50
-
51
- # 音声ファイルのURLをJSONで返す
52
- return jsonify({'audio_url': audio_url})
53
-
54
- @app.route('/')
55
- def portal():
56
- return render_template('portal.html')
57
-
58
  @app.route('/flashcards')
59
  def index():
60
  set_name = request.args.get('set', 'A')
@@ -85,52 +56,19 @@ def index():
85
  japanese = translation_dict_G[english]
86
  total = len(english_sentences_G)
87
 
88
- # 初回の音声ファイルを生成
89
  audio_url = url_for('static', filename=f"audio/{set_name}_{index}.mp3")
90
  generate_audio(english, set_name, index)
91
 
92
- return render_template('index.html', set_name=set_name, index=index, english=english, japanese=japanese, total=total, audio_url=audio_url)
93
-
94
- @app.route('/next')
95
- def next_card():
96
- set_name = request.args.get('set', 'A')
97
- index = int(request.args.get('index', 0)) + 1
98
-
99
- if set_name == 'A' and index >= len(english_sentences_A):
100
- index = 0
101
- elif set_name == 'B' and index >= len(english_sentences_B):
102
- index = 0
103
- elif set_name == 'C' and index >= len(english_sentences_C):
104
- index = 0
105
- elif set_name == 'D' and index >= len(english_sentences_D):
106
- index = 0
107
- elif set_name == 'F' and index >= len(english_sentences_F):
108
- index = 0
109
- elif set_name == 'G' and index >= len(english_sentences_G):
110
- index = 0
111
-
112
- return redirect(url_for('index', set=set_name, index=index))
113
-
114
- @app.route('/prev')
115
- def prev_card():
116
- set_name = request.args.get('set', 'A')
117
- index = int(request.args.get('index', 0)) - 1
118
-
119
- if index < 0:
120
- if set_name == 'A':
121
- index = len(english_sentences_A) - 1
122
- elif set_name == 'B':
123
- index = len(english_sentences_B) - 1
124
- elif set_name == 'C':
125
- index = len(english_sentences_C) - 1
126
- elif set_name == 'D':
127
- index = len(english_sentences_D) - 1
128
- elif set_name == 'F':
129
- index = len(english_sentences_F) - 1
130
- elif set_name == 'G':
131
- index = len(english_sentences_G) - 1
132
-
133
- return redirect(url_for('index', set=set_name, index=index))
134
 
135
  if __name__ == '__main__':
136
- app.run(debug=True, host="0.0.0.0", port=7860)
 
1
  from flask import Flask, render_template, request, redirect, url_for, jsonify
2
  from gtts import gTTS
3
  import os
4
+
5
  app = Flask(__name__)
6
 
7
  # 音声ファイルの保存ディレクトリ
 
25
  tts.save(filename)
26
  return filename
27
 
28
+ # フラッシュカードの内容をJSONで返す
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  @app.route('/flashcards')
30
  def index():
31
  set_name = request.args.get('set', 'A')
 
56
  japanese = translation_dict_G[english]
57
  total = len(english_sentences_G)
58
 
59
+ # 音声ファイルの生成
60
  audio_url = url_for('static', filename=f"audio/{set_name}_{index}.mp3")
61
  generate_audio(english, set_name, index)
62
 
63
+ # フラッシュカードの情報をJSONで返す
64
+ return jsonify({
65
+ 'set_name': set_name,
66
+ 'index': index,
67
+ 'total': total,
68
+ 'english': english,
69
+ 'japanese': japanese,
70
+ 'audio_url': audio_url
71
+ })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  if __name__ == '__main__':
74
+ app.run(debug=True, host="0.0.0.0", port=7860)