Beispiel #1
0
    def test_simple(self):
        with TestClient(self.app) as client:
            response = client.post("/", json={"inputs": "This is some text"})

        self.assertEqual(
            response.status_code,
            200,
        )
        self.assertEqual(response.headers["content-type"], "audio/flac")
        audio = ffmpeg_read(response.content)
        self.assertEqual(len(audio.shape), 1)
        self.assertGreater(audio.shape[0], 1000)
    def test_webm_audiofile(self):
        bpayload = self.read("sample1.webm")

        with TestClient(self.app) as client:
            response = client.post("/", data=bpayload)

        self.assertEqual(
            response.status_code,
            200,
        )
        self.assertEqual(response.header["content-type"], "audio/wav")
        audio = ffmpeg_read(response.content)
        self.assertEqual(audio.shape, (10, ))
    def test_simple(self):
        bpayload = self.read("sample1.flac")

        with TestClient(self.app) as client:
            response = client.post("/", data=bpayload)

        self.assertEqual(
            response.status_code,
            200,
        )
        self.assertEqual(response.headers["content-type"], "audio/flac")
        audio = ffmpeg_read(response.content)

        self.assertEqual(len(audio.shape), 1)
        self.assertGreater(audio.shape[0], 1000)
    def test_dual_channel_audiofile(self):
        bpayload = self.read("sample1_dual.ogg")
        with TestClient(self.app) as client:
            response = client.post("/", data=bpayload)

        self.assertEqual(
            response.status_code,
            200,
        )
        self.assertEqual(response.headers["content-type"], "application/json")
        audio = json.loads(response.content)

        self.assertTrue(isinstance(audio, list))
        self.assertEqual(set(audio[0].keys()), {"blob", "content-type", "label"})

        data = base64.b64decode(audio[0]["blob"])
        wavform = ffmpeg_read(data, 16000)
        self.assertGreater(wavform.shape[0], 1000)
        self.assertTrue(isinstance(audio[0]["content-type"], str))
        self.assertTrue(isinstance(audio[0]["label"], str))