Skip to content

Commit 17971f8

Browse files
author
The dialog Authors
committed
Update decoders to correctly handle pcm data
PiperOrigin-RevId: 894304986
1 parent 44599a4 commit 17971f8

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

dialog/_src/audio_helper.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,13 @@ class _Decoder:
216216

217217
@classmethod
218218
def from_mime_type(cls, mime_type: str) -> Self | None:
219-
"""Returns whether the mime type matches."""
219+
"""Returns the decoder matching the mime type, or None."""
220220
mime_type = mime_type.lower()
221+
# Strip parameters from mime type.
222+
# e.g. 'audio/pcm;rate=24000' -> 'audio/pcm'
223+
base_mime_type = mime_type.split(';')[0].strip()
221224
for subcls in cls.__subclasses__():
222-
if mime_type in subcls.MIME_TYPES:
225+
if mime_type in subcls.MIME_TYPES or base_mime_type in subcls.MIME_TYPES:
223226
return subcls()
224227

225228
return None
@@ -274,8 +277,7 @@ def decode(self, data: gemini_example_pb2.Audio) -> bytes:
274277
wav_file.setsampwidth(array.dtype.itemsize)
275278
wav_file.setframerate(data.sample_rate)
276279
wav_file.writeframes(array.tobytes())
277-
278-
return f.getvalue()
280+
return f.getvalue()
279281

280282

281283
def _validate_pcm_int_16(data: np.ndarray) -> None:

0 commit comments

Comments
 (0)