|
1 | 1 | import os |
2 | | - |
3 | | -os.environ["no_proxy"] = "localhost, 127.0.0.1, 0.0.0.0" |
4 | 2 | import re |
5 | 3 | import subprocess |
6 | 4 | import time |
7 | 5 | import wave |
8 | 6 | from pathlib import Path |
9 | 7 |
|
10 | | -import httpx |
11 | 8 | import numpy as np |
12 | 9 | import ormsgpack |
13 | 10 | import psutil |
14 | 11 | import pyaudio |
| 12 | +import requests |
15 | 13 | import sounddevice as sd |
16 | 14 | from PyQt6.QtCore import QMutex, QMutexLocker, QThread, pyqtSignal |
17 | 15 |
|
@@ -193,32 +191,29 @@ def _process_audio_stream(self): |
193 | 191 | f = open(self.audio_path, "wb") |
194 | 192 |
|
195 | 193 | self.f = f |
196 | | - with httpx.Client() as client: |
197 | | - with client.stream( |
198 | | - "POST", |
199 | | - self.backend, |
200 | | - content=ormsgpack.packb( |
201 | | - request, option=ormsgpack.OPT_SERIALIZE_PYDANTIC |
202 | | - ), |
203 | | - headers={ |
204 | | - "authorization": f"Bearer {self.api_key}", |
205 | | - "content-type": "application/msgpack", |
206 | | - }, |
207 | | - timeout=None, |
208 | | - ) as response: |
209 | | - for chunk in response.iter_bytes(chunk_size=frames_per_buffer): |
210 | | - if first_packet_time is None: |
211 | | - first_packet_time = self.elapsed |
212 | | - self.time_worker.stop() |
213 | | - |
214 | | - if self.is_interrupted: |
215 | | - return |
216 | | - |
217 | | - if streaming: |
218 | | - stream.write(chunk) |
219 | | - f.writeframesraw(chunk) |
220 | | - else: |
221 | | - f.write(chunk) |
| 194 | + response = requests.post( |
| 195 | + self.backend, |
| 196 | + data=ormsgpack.packb(request, option=ormsgpack.OPT_SERIALIZE_PYDANTIC), |
| 197 | + stream=streaming, |
| 198 | + headers={ |
| 199 | + "authorization": f"Bearer {self.api_key}", |
| 200 | + "content-type": "application/msgpack", |
| 201 | + }, |
| 202 | + ) |
| 203 | + |
| 204 | + for chunk in response.iter_content(chunk_size=frames_per_buffer): |
| 205 | + if first_packet_time is None: |
| 206 | + first_packet_time = self.elapsed |
| 207 | + self.time_worker.stop() |
| 208 | + |
| 209 | + if self.is_interrupted: |
| 210 | + return |
| 211 | + |
| 212 | + if streaming: |
| 213 | + stream.write(chunk) |
| 214 | + f.writeframesraw(chunk) |
| 215 | + else: |
| 216 | + f.write(chunk) |
222 | 217 |
|
223 | 218 | self.finish() |
224 | 219 |
|
|
0 commit comments