Skip to content

Commit

Permalink
Support audio data in np.int8 format in the gr.Audio component (#…
Browse files Browse the repository at this point in the history
…7112)

* fix#7099

Fix for Audio data cannot be converted automatically from int8 to 16-bit int format

* add changeset

* add changeset

* fix'

* processing

---------

Co-authored-by: gradio-pr-bot <[email protected]>
Co-authored-by: Abubakar Abid <[email protected]>
  • Loading branch information
3 people authored Jan 22, 2024
1 parent 94aa271 commit 217bfe3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/big-bananas-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Support audio data in `np.int8` format in the `gr.Audio` component
6 changes: 5 additions & 1 deletion gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def convert_to_16_bit_wav(data):
data = data.astype(np.int16)
elif data.dtype == np.int32:
warnings.warn(warning.format(data.dtype))
data = data / 65538
data = data / 65536
data = data.astype(np.int16)
elif data.dtype == np.int16:
pass
Expand All @@ -355,6 +355,10 @@ def convert_to_16_bit_wav(data):
warnings.warn(warning.format(data.dtype))
data = data * 257 - 32768
data = data.astype(np.int16)
elif data.dtype == np.int8:
warnings.warn(warning.format(data.dtype))
data = data * 256
data = data.astype(np.int16)
else:
raise ValueError(
"Audio data cannot be converted automatically from "
Expand Down

0 comments on commit 217bfe3

Please sign in to comment.