mirror of
https://github.com/mudler/LocalAI.git
synced 2026-09-12 14:22:11 -04:00
Expose diffusers audio pipelines through the existing sound-generation RPC. AudioLDM2 can now return PCM WAV output from the model gallery without a separate backend. Assisted-by: Codex:gpt-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
25 lines
688 B
Python
25 lines
688 B
Python
import array
|
|
import sys
|
|
import wave
|
|
|
|
|
|
def write_pcm_wav(destination, samples, sampling_rate):
|
|
"""Write normalized floating-point audio samples as mono 16-bit PCM."""
|
|
pcm = array.array(
|
|
"h",
|
|
(
|
|
max(-32768, min(32767, round(float(sample) * 32768)))
|
|
for sample in samples
|
|
),
|
|
)
|
|
if pcm.itemsize != 2:
|
|
raise RuntimeError("16-bit PCM requires two-byte signed integers")
|
|
if sys.byteorder != "little":
|
|
pcm.byteswap()
|
|
|
|
with wave.open(destination, "wb") as output:
|
|
output.setnchannels(1)
|
|
output.setsampwidth(2)
|
|
output.setframerate(sampling_rate)
|
|
output.writeframes(pcm.tobytes())
|