termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.15k stars 3.02k forks source link

[Bug]:Portaudio couldn't detect audio device #21545

Closed afrhan-repo closed 3 weeks ago

afrhan-repo commented 3 weeks ago

Problem description

I tried to use pyaudio library to record my audio.But after initialising pulse audio server and giving required permissions to termux api it doesn't work.

What steps will reproduce the bug?

Install portaudio version(19.07) from apt and install pyaudio library.Then executing this code

import pyaudio
import wave

chunk = 1024  # Record in chunks of 1024 samples
sample_format = pyaudio.paInt16  # 16 bits per sample
channels = 2
fs = 44100  # Record at 44100 samples per second
seconds = 3
filename = "output.wav"

p = pyaudio.PyAudio()  # Create an interface to PortAudio

print('Recording')

stream = p.open(format=sample_format,
                channels=channels,
                rate=fs,
                frames_per_buffer=chunk,
                input=True)

frames = []  # Initialize array to store frames

# Store data in chunks for 3 seconds
for i in range(0, int(fs / chunk * seconds)):
    data = stream.read(chunk)
    frames.append(data)

# Stop and close the stream 
stream.stop_stream()
stream.close()
# Terminate the PortAudio interface
p.terminate()

print('Finished recording')

# Save the recorded data as a WAV file
wf = wave.open(filename, 'wb')
wf.setnchannels(channels)
wf.setsampwidth(p.get_sample_size(sample_format))
wf.setframerate(fs)
wf.writeframes(b''.join(frames))
wf.close()

,it throws this error Traceback (most recent call last): File "/data/data/com.termux/files/home/main1.py", line 15, in <module> stream = p.open(format=sample_format, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/pyaudio/__init__.py", line 639, in open stream = PyAudio.Stream(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/pyaudio/__init__.py", line 441, in __init__ self._stream = pa.open(**arguments) ^^^^^^^^^^^^^^^^^^^^ OSError: [Errno -9996] Invalid input device (no default output device)

What is the expected behavior?

It should work without rasing any error

System information

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=31431
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.dev/apt/termux-main stable main
# x11-repo (sources.list.d/x11.list)
deb https://packages-cf.termux.dev/apt/termux-x11 x11 main
# tur-repo (sources.list.d/tur.list)
deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
# root-repo (sources.list.d/root.list)
deb https://packages-cf.termux.dev/apt/termux-root root stable
# sources.list.d/termux-adb.list
deb https://nohajc.github.io termux extras
Updatable packages:
neovim/stable 0.10.1-1 aarch64 [upgradable from: 0.10.1]
openssh-sftp-server/stable 9.9p1-3 aarch64 [upgradable from: 9.9p1-2]
openssh/stable 9.9p1-3 aarch64 [upgradable from: 9.9p1-2]
termux-tools version:
1.43.5
Android version:
10
Kernel build information:
Linux localhost 4.9.186-perf-g131f907 #1 SMP PREEMPT Thu Apr 8 17:20:44 WIB 2021 aarch64 Android
Device manufacturer:
Xiaomi
Device model:
Redmi Y3
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api versionCode:51
afrhan-repo commented 3 weeks ago

I think it is not possible in termux because portaudio is build without any audio backend support.Now I am going to close it