-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (33 loc) Β· 1.3 KB
/
Copy pathmain.py
File metadata and controls
43 lines (33 loc) Β· 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from flask import Flask, request
from flask_restx import Api, Resource, reqparse
import sentiment_prediction
import speech_recognition as sr
from gtts import gTTS
app = Flask(__name__)
api = Api(app, version='3.0', title='Folder API', description='Swagger λ¬Έμ', doc="/api-docs")
test_api = api.namespace('STT', description='μμ±μΈμ API')
prediction_api = api.namespace('prediction', description='κ°μ λΆμ κΈλΆμ API')
@test_api.route('/STT')
class Test(Resource):
def get(self):
try:
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
try:
stt = r.recognize_google(audio, language='ko-KR')
return stt
except sr.UnknownValueError:
print('μ€λμ€λ₯Ό μ΄ν΄ν μ μμ΅λλ€.')
except sr.RequestError as e:
print(f'μλ¬κ° λ°μνμμ΅λλ€. μλ¬μμΈ : {e}')
except KeyboardInterrupt:
pass
@prediction_api.route('/<string:text>')
class SentimentPredict(Resource):
def get(self, text):
predict = sentiment_prediction.Prediction()
result = predict.text_prediction(text)
return result
if __name__ == '__main__':
app.run('0.0.0.0', port=8000)