Вот мой flask python код
@app.route("/text-to-speech", methods=['POST'])
def tts():
userText = request.form['msg']
engine = pyttsx3.init()
engine.say(userText)
engine.runAndWait()
return render_template('tts.html')
, и это tts. html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href= "{{ url_for('static',filename='styles/chatter.css') }}" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<div id="home">
<a href="/">Home <i class="fa fa-home"></i></a>
</div>
<h1>Text-to-Speech</h1>
<div>
<div id="chatimage">
<img src="{{url_for('static', filename='images/image.png')}}" alt="joe">
</div>
<div id="chatbox">
<p class="botText"><span>>>TTS</span></p>
</div>
<div id="userInput">
<form method="POST">
<label for="textInput"></label>
<input id="textInput" type="text" name="msg" placeholder="">
<input id="buttonInput" type="submit" value="Read">
</form>
</div>
</div>
</body>
</html>
При первом вводе предложения это читай как надо. Если я пытаюсь ввести второй раз, я получаю
builtins.RuntimeError
RuntimeError: run loop already started
, который ломает мою страницу.
Это вся страница с ошибкой:
builtins.RuntimeError
RuntimeError: run loop already started
Traceback (most recent call last)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/anthi/Desktop/nlp-site/app.py", line 60, in tts
engine.runAndWait()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyttsx3/engine.py", line 177, in runAndWait
raise RuntimeError('run loop already started')
RuntimeError: run loop already started
Кто-нибудь знает, что мне делать? Есть ли способ убить двигатель или что-то в этом роде, чтобы он был заново инициализирован?