Open tathastu871 opened 4 years ago
Try to launch pulseaudio daemon manually and load module-sles-source
.
pulseaudio &
pactl load-module module-sles-source
No, Pulseaudio won't work here. Termux uses audio drivers compatible with Android OS, specifically ones which use OpenSLES and AAudio. Ubuntu doesn't have them. But even if has, they won't be compatible with Android's Hardware Abstraction Layer.
ALSA won't work either. Most Android devices do not have support for it on kernel level, others which have it will require root in order to access devices exposed through /dev
.
Error after trying following commands
dbus-launch --exit-with-session pulseaudio --start --daemon pulseaudio & pactl load-module module-sles-source
Traceback (most recent call last):
File "t.py", line 14, in <module>
stream = audio.open(format=FORMAT, channels=CHANNELS,
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9998] Invalid number of channels
When tried only pulseaudio & pactl load-module module-sles-source Following error occured
[pulseaudio] source.c: Assertion 'pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0' failed at /home/builder/.termux-build/pulseaudio/src/src/pulsecore/source.c:1155, function pa_usec_t pa_source_get_latency(pa_source *)(). Aborting.
Traceback (most recent call last):
File "t.py", line 14, in <module>
stream = audio.open(format=FORMAT, channels=CHANNELS,
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9996] Invalid input device (no default output device)
[1]+ Aborted pulseaudio
Another thing i observed is that when the script is run in termux it gets into background and that may be reason it strucks at recording... and does not actually record and we need to ctrl+z or pkill to exit. But in ubuntu termux script does not show such behaviour. Please try executing script in your device and comment if it runs properly or not.
I think pyaudio can use portaudio api. I have portaudio working over pulseaudio in my apt repo.
I think pyaudio can use portaudio api. I have portaudio working over pulseaudio in my apt repo.
Script seems to be initialised without any errors and works till print ("recording...") line but after that instead of recording it gets into background and runs infinitely and not recording.
However this problem is only in termux and not in proot
This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Any updates Because i too get this error https://github.com/termux/termux-packages/issues/17402#issue-1796107620
I believe OpenSL ES source module for Pulseaudio is broken on modern Android and needs to be fixed or enhanced.
It is advised to use termux-microphone-record
from termux-api
package to record audio for the time being.
still not working(
I don't know termux team is busy or what but the issue is still same after 4years with no progress @termux please fix this asap
Please don't ping the entire org for a "is it done yet" question.
Instead of asking to "fix it asap", contribute.
Hmm make sense I can try to fix
I can assure you that openSl Es source modules
work fine for PulseAudio
They recorded audio and Pluse Audio play them too
The main issue is PyAudio is not recogniseing PulseAudio Stream for some reason
I think I have go through pyaudio code to figure how it works
Looks like pyaudio uses PortAudio So let's see if PortAudio Recognise Plus Audio
Our portaudio seems to disable all audio backends (neither supported by Termux):
TERMUX_PKG_DEPENDS="libc++"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
--enable-cxx
--without-alsa
--without-jack
--without-oss
--without-asihpi
ac_cv_lib_pthread_pthread_create=yes
ac_cv_lib_rt_clock_gettime=yes
"
however its configure script suggests that Pulseaudio isn't supported anyway:
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-alsa Enable support for ALSA [autodetect]
--with-jack Enable support for JACK [autodetect]
--with-oss Enable support for OSS [autodetect]
--with-asihpi Enable support for ASIHPI [autodetect]
--with-winapi Select Windows API support
([wmme|directx|asio|wasapi|wdmks][,...]) [wmme]
--with-asiodir ASIO directory [/usr/local/asiosdk2]
--with-dxdir DirectX directory [/usr/local/dx7sdk]
--with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use
both]
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-sysroot=DIR Search for dependent libraries within DIR
(or the compiler's sysroot if not specified).
README also doesn't mention pulse:
### Host API Implementations:
src/hostapi/alsa = Advanced Linux Sound Architecture (ALSA)
src/hostapi/asihpi = AudioScience HPI
src/hostapi/asio = ASIO for Windows and Macintosh
src/hostapi/coreaudio = Macintosh Core Audio for OS X
src/hostapi/dsound = Windows Direct Sound
src/hostapi/jack = JACK Audio Connection Kit
src/hostapi/oss = Unix Open Sound System (OSS)
src/hostapi/wasapi = Windows Vista WASAPI
src/hostapi/wdmks = Windows WDM Kernel Streaming
src/hostapi/wmme = Windows MultiMedia Extensions (MME)
This one may work: https://github.com/its-pointless/termux-packages/commit/70c4016230d87155591d7bb1b951959e06dd44e1
It is portaudio build recipe for old Termux community repo.
Is it works anymore Someone told me it is not maintained anymore.
If it works then many issue such as =>
Update Termux Packages:
pkg update
pkg upgrade
Install wget:
pkg install wget
Download PortAudio Package:
wget https://its-pointless.github.io/files/24/dists/termux/extras/binary-arm/portaudio_20180920-1_arm.deb
Install the Package:
dpkg -i portaudio_20180920-1_arm.deb
Fix Dependencies:
apt --fix-broken install
Verify Installation:
dpkg -l | grep portaudio
ImportError: dlopen failed: library "libportaudio.so.2" not found: needed by /data/data/com.termux/files/usr/lib/python3.11/site-packages/pyaudio/_portaudio.cpython-311.so in namespace (default)
Locate libportaudio.so
:
find /data/data/com.termux/files/usr/lib -name "libportaudio.so*"
Create Symbolic Link:
ln -s /data/data/com.termux/files/usr/lib/libportaudio.so /data/data/com.termux/files/usr/lib/libportaudio.so.2
For other cpu types you can follow same instructions just download the .deb file accordingly
Ahh but now there is a new issue PortAudio is recogniseing PulseAudio Stream but not recording it.
PulseAudio ✅ OpenSL ES source module ✅ PortAudio ❌ PyAudio✅
OpenSl Module ------- PulseAudio ----- PortAudio ----- PyAudio
Why PortAudio is recogniseing PulseAudio Stream but not Recording it
Problem description
Created a pyaudio script t.py to record sound and export it as wav file. Problem:In termux the file shows that it started recording but strucks at it and does not stop and requires stopping script with ctrl+z while ctrl+c did not workit does not write any recording to wav. Means no recording. The script is made to record 5 seconds of audio
Script content:
Steps to reproduce
Expected behavior
Recording of 5 seconds audio in wav file Additional information
Tried solution: Installed ubuntu on termux with vnc server x11 working and on it tried to run the script, and following error is obtained: Error log from ubuntu installed on termux is given below
Then tried another solution dbus-launch --exit-with-session pulseaudio --start --daemon as non root also tried dbus-launch --exit-with-session pulseaudio --start --daemon --system --disallow-exit as root user python t.py This time script ran and stopped after 5 seconds and file.wav is also created but it was mute no audio was actually recorded.
And output is
ls results shown file.wav but it was having no sound.
However on termux script keeps working infinitely and does not stop after 5 seconds and we need to force stop it with ctrl+z, while with ubuntu on termux script rans records and stops and creates output but is muted or no actual sound recorded Termux is been provided with microphone access permission using termux-microphone-record api.
Other solutions tried: sudo jackd -d alsa to run jack server but in ended with following error: