Accept streamed browser audio uploads at transcription endpoint
This commit is contained in:
1 parent
cbf5f19c97
commit
2933f3aa1e
3 files changed
+61
-6
No files matched your search
+21
@@ -24,6 +24,27 @@ class STTTests(unittest.TestCase):
|
||||
s=STT(None,None,SimpleNamespace(status=lambda:{'active':None}))
|
||||
with self.assertRaises(ValueError):s.build()
|
||||
|
||||
class BrowserUploadTests(unittest.TestCase):
|
||||
def handler(self,body,headers=None):
|
||||
return SimpleNamespace(headers=headers or {'Transfer-Encoding':'chunked'},rfile=io.BytesIO(body))
|
||||
def test_chunked_upload(self):
|
||||
from stt import read_chunked_upload
|
||||
self.assertEqual(read_chunked_upload(self.handler(b'3\r\nabc\r\n2;ext=yes\r\nde\r\n0\r\n\r\n'),5),b'abcde')
|
||||
def test_invalid_chunked_uploads(self):
|
||||
from stt import read_chunked_upload
|
||||
for body in (b'6\r\nabcdef\r\n0\r\n\r\n',b'zz\r\n',b'3\r\nab',b'0\r\nx: y\r\n\r\n'):
|
||||
with self.assertRaises(ValueError):read_chunked_upload(self.handler(body),5)
|
||||
with self.assertRaises(ValueError):read_chunked_upload(self.handler(b'0\r\n\r\n',{'Transfer-Encoding':'chunked','Content-Length':'0'}),5)
|
||||
def test_normalizes_non_16khz_wav(self):
|
||||
from stt import normalize_transcription_audio
|
||||
out=io.BytesIO()
|
||||
with wave.open(out,'wb') as w:w.setnchannels(2);w.setsampwidth(2);w.setframerate(48000);w.writeframes(bytes(4800*4))
|
||||
converted=normalize_transcription_audio(out.getvalue());validate_wav(converted)
|
||||
with wave.open(io.BytesIO(converted)) as w:self.assertAlmostEqual(w.getnframes()/w.getframerate(),.1,places=2)
|
||||
def test_rejects_invalid_audio(self):
|
||||
from stt import normalize_transcription_audio
|
||||
with self.assertRaisesRegex(ValueError,'Audioformat'):normalize_transcription_audio(b'not an audio file')
|
||||
|
||||
class ReferenceTranscriptionTests(unittest.TestCase):
|
||||
def test_reference_normalized_and_transcribed_without_download(self):
|
||||
import threading
|
||||
|
||||
Reference in new issue
Block a user