Spaces:
Build error
Build error
prev chunk
Browse files- client/src/main.py +24 -10
client/src/main.py
CHANGED
@@ -24,7 +24,7 @@ logger = logging.getLogger(__name__)
|
|
24 |
TRANSCRIBING_SERVER = os.getenv('TRANSCRIBING_SERVER', "http://localhost:3535/transcribe")
|
25 |
|
26 |
|
27 |
-
def main():
|
28 |
recording_duration = 1
|
29 |
sample_rate = 16000
|
30 |
energy_threshold = 300
|
@@ -78,7 +78,9 @@ def main():
|
|
78 |
start = time.time()
|
79 |
print('start req')
|
80 |
response = httpx.post(TRANSCRIBING_SERVER, data=serialized)
|
|
|
81 |
print('req done', response.text, response.status_code, time.time() - start)
|
|
|
82 |
|
83 |
# text = transcribe_model.transcribe(current_audio_chunk.audio_array)
|
84 |
# sentence = Sentence(
|
@@ -107,14 +109,23 @@ def main():
|
|
107 |
# print(sentence.text) # noqa: T201
|
108 |
break
|
109 |
|
110 |
-
|
111 |
-
for i in range(minimum, maximum + 1):
|
112 |
-
|
113 |
-
|
114 |
|
115 |
async def sse(request):
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
def test(request):
|
120 |
return "hello world"
|
@@ -128,15 +139,18 @@ app = Starlette(debug=True, routes=routes)
|
|
128 |
app.add_middleware(CORSMiddleware, allow_origins=['*'], allow_methods=['*'], allow_headers=['*'])
|
129 |
|
130 |
|
131 |
-
def server():
|
|
|
132 |
uvicorn.run(app, host="0.0.0.0", port=8343, log_level='info')
|
133 |
|
134 |
|
135 |
if __name__ == '__main__':
|
136 |
-
|
|
|
|
|
137 |
main_thread.start()
|
138 |
|
139 |
-
server_thread = threading.Thread(target=server)
|
140 |
server_thread.start()
|
141 |
|
142 |
main_thread.join()
|
|
|
24 |
TRANSCRIBING_SERVER = os.getenv('TRANSCRIBING_SERVER', "http://localhost:3535/transcribe")
|
25 |
|
26 |
|
27 |
+
def main(transcriptions_queue):
|
28 |
recording_duration = 1
|
29 |
sample_rate = 16000
|
30 |
energy_threshold = 300
|
|
|
78 |
start = time.time()
|
79 |
print('start req')
|
80 |
response = httpx.post(TRANSCRIBING_SERVER, data=serialized)
|
81 |
+
transcription = response.json()['transcribe']
|
82 |
print('req done', response.text, response.status_code, time.time() - start)
|
83 |
+
transcriptions_queue.put(transcription)
|
84 |
|
85 |
# text = transcribe_model.transcribe(current_audio_chunk.audio_array)
|
86 |
# sentence = Sentence(
|
|
|
109 |
# print(sentence.text) # noqa: T201
|
110 |
break
|
111 |
|
112 |
+
|
113 |
+
# for i in range(minimum, maximum + 1):
|
114 |
+
# await asyncio.sleep(0.9)
|
115 |
+
# yield dict(data=i)
|
116 |
|
117 |
async def sse(request):
|
118 |
+
async def event_publisher():
|
119 |
+
try:
|
120 |
+
while True:
|
121 |
+
text = transcriptions_queue.get()
|
122 |
+
yield dict(data=text)
|
123 |
+
await asyncio.sleep(0.2)
|
124 |
+
except asyncio.CancelledError as e:
|
125 |
+
print(f"Disconnected from client (via refresh/close) {request.client}")
|
126 |
+
|
127 |
+
return EventSourceResponse(event_publisher())
|
128 |
+
|
129 |
|
130 |
def test(request):
|
131 |
return "hello world"
|
|
|
139 |
app.add_middleware(CORSMiddleware, allow_origins=['*'], allow_methods=['*'], allow_headers=['*'])
|
140 |
|
141 |
|
142 |
+
def server(transcriptions_queue):
|
143 |
+
app.state.transcriptions_queue = transcriptions_queue
|
144 |
uvicorn.run(app, host="0.0.0.0", port=8343, log_level='info')
|
145 |
|
146 |
|
147 |
if __name__ == '__main__':
|
148 |
+
transcriptions_queue = Queue()
|
149 |
+
|
150 |
+
main_thread = threading.Thread(target=main, args=(transcriptions_queue,))
|
151 |
main_thread.start()
|
152 |
|
153 |
+
server_thread = threading.Thread(target=server, args=(transcriptions_queue,))
|
154 |
server_thread.start()
|
155 |
|
156 |
main_thread.join()
|