Spaces:
Sleeping
Sleeping
File size: 482 Bytes
c0a983b ec10d0e c0a983b ec10d0e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from io import BytesIO
import soundfile
import numpy as np
from PIL import Image
def audio_array_to_buffer(audio_array: np.array, sample_rate: int) -> BytesIO:
buffer = BytesIO()
soundfile.write(buffer, audio_array, sample_rate, format="wav")
buffer.seek(0)
return buffer
def img_to_bytes(
image: Image.Image, img_format: Literal["PNG", "JPEG"] = "PNG"
) -> bytes:
buffer = BytesIO()
image.save(buffer, format=img_format)
return buffer.getvalue() |