We have moved to a new Sailfish OS Forum. Please start new discussions there.
1

portaudio / python3 sounddevice

asked 2018-10-06 14:21:00 +0300

Mario gravatar image

Hi, I'm trying to use "sounddevice" (with python3 in the terminal) to run on my SailfishX, in order to record audio.

After solving some issues to install the python module, I now get a runtime error that I'm not able to fix.

Installation:

Usage / Errors:

python3:

import sounddevice as sd
sd.check_input_settings()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nemo/.local/lib/python3.4/site-packages/sounddevice.py", line 601, in check_input_settings
    _check(_lib.Pa_IsFormatSupported(parameters, _ffi.NULL, samplerate))
  File "/home/nemo/.local/lib/python3.4/site-packages/sounddevice.py", line 2572, in _check
    raise PortAudioError(errormsg, err)

I tried several combinations of settings. All the same error. Also, I tried just recording (without checking first) but also a similar error.

Is anyone using sounddevice or PyAudio or PortAudio successfully on sailfish? Can you give my any working example to record audio with python on sailfish?

I noticed Saera and espeak use PortAudio somehow but I don't think they use python.

edit retag flag offensive close delete

1 Answer

Sort by » oldest newest most voted
1

answered 2018-10-06 16:02:32 +0300

Mario gravatar image

By chance I found a workaround using the pulseaudio tool pacat:

#!/usr/bin/python3

print("Use with headphones!!")

import numpy
import subprocess

proc_in = subprocess.Popen(('parec', "--channels=1"), stdout=subprocess.PIPE)
proc_out = subprocess.Popen(('pacat', "--channels=1"), stdin=subprocess.PIPE)

buf_size = 512

for i in range(5000):
    ## read audio from microphone
    _incoming_data = numpy.fromstring(proc_in.stdout.read(buf_size*4), dtype=numpy.int16)

    ## show volume level
    volume_norm = numpy.linalg.norm(_incoming_data)
    print(len(_incoming_data), volume_norm)

    ## write audio to speakers
    proc_out.stdin.write(_incoming_data.tobytes())


## close
proc_in.kill()
proc_out.kill()
proc_in.wait()
proc_out.wait()

This does not solve the actual issue, but gives me basically the same numpy arrays as sounddevice would give. Obviously there is some overhead due to the extra process and the pipe. Also, there is a small delay, definitely larger than with sounddevice (tested on my laptop), but okay..

Still, if anyone got sounddevice working I'm still interested.

edit flag offensive delete publish link more

Comments

but there are already voice and call recording apps

deloptes ( 2018-10-30 14:00:26 +0300 )edit

For recording that's true. But I need it for live processing and streaming.

Mario ( 2019-04-07 14:13:51 +0300 )edit
Login/Signup to Answer

Question tools

Follow
5 followers

Stats

Asked: 2018-10-06 14:21:00 +0300

Seen: 467 times

Last updated: Oct 06 '18