Sign inSign up

alessio21/play-numpy-array

By alessio21

•Updated over 2 years ago

Image
0

325

alessio21/play-numpy-array repository overview

⁠Generate audio from a numpy array.

This image allow you to generate audio from a numpy array: it exposes a POST API so just pass it an array as input and it will return the audio represented by it!

Container exposed port: 2865.

Endpoint url: "/send_array"

⁠Requirements:

You only need to have Pulseaudio⁠ running on your pc. PulseAudio is a sound server system for Unix-like operating systems but you can use it also on Windows.

Pulseaudio for Windows instructions:

  • download the zip file here⁠, extract and place it in a folder of your choice
  • go to the etc/pulse/daemon.conf file, uncomment and set the "exit-idle-time" parameter equal to -1
  • go to the etc/pulse/default.pa file, search for "load-module module-native-protocol-tcp", uncomment it and on the same line add "listen=0.0.0.0 auth-anonymous=1"
  • open Windows PowerShell, move to the previous chosen folder and run: ".\pulseaudio-1.1\bin\pulseaudio.exe --use-pid-file=false -D"

Congratulations! Now you should have pulseaudio running on your pc and you are ready to use this image.

⁠How to run:

Open the command prompt and launch the container:

docker run -p 2865:2865 alessio21/play-numpy-array

Send your array to http://localhost:2865/send_array⁠ :

import numpy as np
import requests

API_URL = "http://localhost:2865/send_array"

#create the audio array
fs = 16000 # Hz
T = 1. # second, arbitrary length of tone

t = np.arange(0, T, 1/fs)
x = 0.5 * np.sin(2*np.pi*1000*t) 
x  = (x*32768).astype(np.float32) 

#send the array to the container
payload = {"audio_array":x.tolist()}

resp = requests.post(API_URL, json=payload)
response = resp.json()
print(response)

⁠Usage example:

In this repository⁠ the image is used to generate audio for a voice chatbot (see the docker-compose.yml file).

Tag summary

Content type

Image

Digest

sha256:55b1eca3f…

Size

71.6 MB

Last updated

over 2 years ago

docker pull alessio21/play-numpy-array