Skip to content

Commit

Permalink
Add WAV header option for SST
Browse files Browse the repository at this point in the history
This adds support for sending raw 16-bit 16Khz mono audio to the STT
endpoint of the Rhasspy HTTP API without a WAV header, thus providing a
convenient way to send headerless WAV audio e.g. recorded with PyAudio.
  • Loading branch information
x3a committed Oct 24, 2020
1 parent 19f8be8 commit 12117f5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions rhasspyclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,19 @@ async def train(self, no_cache=False) -> TrainingComplete:

# -------------------------------------------------------------------------

async def speech_to_text(self, wav_data: bytes) -> Transcription:
"""Transcribe WAV audio."""
headers = {"Content-Tyoe": "audio/wav"}
async def speech_to_text(
self, wav_data: bytes, wav_header: bool = True
) -> Transcription:
"""
Transcribe WAV audio.
If wav_header is False, wav_data is expected to be raw 16-bit 16Khz
mono audio without a WAV header.
"""
headers = {"Content-Type": "audio/wav"}
params = {"noheader": "true" if not wav_header else "false"}
async with self.session.post(
self.stt_url, headers=headers, data=wav_data
self.stt_url, headers=headers, params=params, data=wav_data
) as response:
text = await response.text()

Expand Down

0 comments on commit 12117f5

Please sign in to comment.