chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
807 stars 132 forks source link

Could not find PyAudio #389

Open HAKANMAZI opened 3 years ago

HAKANMAZI commented 3 years ago

I installed chaquopy on my Android Studio then ı tried to run below code

import speech_recognition as sr
import time

r = sr.Recognizer()
mic = sr.Microphone()

def transcript(transcript=''):
    with mic as source:
        r.adjust_for_ambient_noise(source)
        audio = r.listen(source)
    try:
        transcript = r.recognize_google(audio,language='tr-TR')
    except sr.UnknownValueError:
        time.sleep(1)
    except sr.RequestError:
        time.sleep(1)

    return transcript

But I got this error

     Caused by: com.chaquo.python.PyException: AttributeError: Could not find PyAudio; check installation
        at <python>.speech_recognition.get_pyaudio(__init__.py:110)
        at <python>.speech_recognition.__init__(__init__.py:79)
        at <python>.konus.<module>(konus.py:5)
        at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:219)
        at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:783)
        at <python>.java.android.importer.exec_module(importer.py:549)
        at <python>.java.android.importer.exec_module(importer.py:594)
        at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:671)
        at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:975)
        at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:991)
        at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1014)
        at <python>.importlib.import_module(__init__.py:127)
        at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModule(chaquopy_java.pyx:156)
        at com.chaquo.python.Python.getModule(Native Method)
mhsmith commented 3 years ago

Thanks for the report. Unfortunately Android doesn't support any of the standard Linux audio APIs, so I think PyAudio / PortAudio would require a new backend in order to work.

If anyone else needs this package, please click the thumbs-up button above and subscribe to this issue, and we may look into it in the future.

askinucuncu commented 3 years ago

Is there any progress on this subject?

mhsmith commented 3 years ago

Not yet, sorry.

MalikSayriii commented 3 years ago

After three days of searching a solution i came to know that it is not compatible with android studio 🥲 i am a beginner/student i wanted to implement PayAudio in my Final year project.. my request is to please make it possible... I there any alternative i can use with my android app ?

mhsmith commented 3 years ago

You can use the standard Android audio APIs directly, either in Java, Kotlin, or in Python using the Chaquopy API. For an example, see here.

nguyentiem commented 1 year ago

i think our goal is to convert speech to text real time. so i have an idea, we pass bytes array as agrument of python function, then python function detect and return text to android . Is this solution possible?

mhsmith commented 1 year ago

Yes, that should be possible. But I don't think we currently support any Python packages which can decode compressed audio, unless there's a pure-Python option I don't know abot. So you'd have to pass the audio as an uncompressed WAV file, or raw PCM.

ObscurusGrassator commented 8 months ago

After 3 years any progress?

Chaquopy version 15.0.1

MacOS 13.5.2

Relevant parts of your build.gradle file

chaquopy {
    defaultConfig {
        version = "3.9"
        buildPython("/Users/xxx/.pyenv/versions/3.9.18/bin/python")
        pip {
            install "tflite_runtime-2.5.0.post1-cp39-cp39-macosx_12_0_arm64.whl"
            install "pyaudio"
            install "openwakeword"
            // https://test.pypi.org/simple/onnxruntime/
            install "onnxruntime-1.16.2-cp39-cp39-macosx_11_0_arm64.whl"
        }
    }
}
android {
    defaultConfig {
        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"

Describe your issue

...
Collecting pyaudio
  Using cached PyAudio-0.2.14.tar.gz (47 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
...
  ERROR: Command errored out with exit status 1:
   command: .../android/app/build/python/env/debug/bin/python .../android/app/build/python/env/debug/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /var/folders/zd/fmk31xcn1q3b09jlpc14k3g00000gn/T/tmp1g_drf5v
       cwd: /private/var/folders/zd/fmk31xcn1q3b09jlpc14k3g00000gn/T/pip-install-sfda6ys4/pyaudio
  Complete output (10 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-13.5-arm64-cpython-39
  creating build/lib.macosx-13.5-arm64-cpython-39/pyaudio
  copying src/pyaudio/__init__.py -> build/lib.macosx-13.5-arm64-cpython-39/pyaudio
  running build_ext
  building 'pyaudio._portaudio' extension
  error: CCompiler.compile: Chaquopy cannot compile native code
  ----------------------------------------
ERROR: Failed to install pyaudio from https://files.pythonhosted.org/packages/26/1d/8878c7752febb0f6716a7e1a52cb92ac98871c5aa522cba181878091607c/PyAudio-0.2.14.tar.gz#sha256=78dfff3879b4994d1f4fc6485646a57755c6ee3c19647a491f790a0895bd2f87.
For assistance, please raise an issue at https://github.com/chaquo/chaquopy/issues.
Chaquopy: Exit status 1

FAILURE: Build failed with an exception. ...

mhsmith commented 8 months ago

No, because as I said above, this would require a substantial amount of work on PyAudio's side.