chaquo / chaquopy

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

"FLAC conversion utility not available" in speech_recognition.recognize_google #311

Open Abhi55Y opened 4 years ago

Abhi55Y commented 4 years ago

No python interpreter configured for the module". Can you please help us to resolve this problem? We are using java android to convert a prerecorded audio file to text for which we are using python support using chaquopy but we are getting the "No python interpreter configured for the module" error.

we are also getting an error: FLAC conversion utility not available

mhsmith commented 4 years ago

No python interpreter configured for the module

As the documentation says, this message is harmless.

we are also getting an error: FLAC conversion utility not available

If your Python library depends on an external program to decode the audio, then that program will need to be installed on the device, which will probably be difficult. I recommend using a WAV file instead.

Abhi55Y commented 4 years ago

We are using .wav file. Then too it is showing me an error: "FLAC conversion utility not available - consider installing the FLAC command line application by running apt-get install flac or your operating system's equivalent"

mhsmith commented 4 years ago

I assume you're using the speech_recognition library. From its source code it looks as if it only tries to load a file as FLAC if it's failed to load it as WAV.

Are you sure you're passing the correct filename? See #144 for advice on this.

If you still can't work it out, please post the full exception trace and the relevant lines of your source code.

Abhi55Y commented 4 years ago

Yes, I'm using the correct file name .wav audio file

MainActivity.java file

package com.example.pythontesting;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

import com.chaquo.python.PyObject;
import com.chaquo.python.Python;
import com.chaquo.python.android.AndroidPlatform;

public class MainActivity extends AppCompatActivity {

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (! Python.isStarted()) {
            Python.start(new AndroidPlatform(this));
        }

        Python python = Python.getInstance();
        PyObject pyObject = python.getModule("audio");
        PyObject obj = pyObject.callAttr("converter");

        textView = findViewById(R.id.text);
        textView.setText(obj.toString());
    }
}

activity.xml file

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

AndroidMenifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.pythontesting">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

build.gradle(project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://chaquo.com/maven" }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath "com.chaquo.python:gradle:7.0.3"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(app)

apply plugin: 'com.android.application'
apply plugin: 'com.chaquo.python'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.pythontesting"
        sourceSets {
            main {
                python {
                    srcDirs = ["src/main/python"]
                    srcDir "additional/dir"
                }
            }
        }
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        python {
            buildPython "C:\\Users\\Aarambh\\AppData\\Local\\Programs\\Python\\Python37\\python.exe"

            pip{
                install "SpeechRecognition"
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Python file

import speech_recognition as sr

# obtain path to "english.wav" in the same folder as this script
from os import path
def converter():
    result=None
    result1=None
    result2=None
    AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "audio.wav")
    # AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "french.aiff")
    # AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "chinese.flac")

    # use the audio file as the audio source
    r = sr.Recognizer()
    with sr.AudioFile(AUDIO_FILE) as source:
        audio = r.record(source)  # read the entire audio file

    # recognize speech using Sphinx
    try:
        #print("Sphinx thinks you said " + r.recognize_sphinx(audio))
        result = r.recognize_sphinx(audio)
    except sr.UnknownValueError:
        result = "Sphinx could not understand audio"
    except sr.RequestError as e:
        result = "Sphinx error; {0}".format(e)

    # recognize speech using Google Speech Recognition
    try:
        # for testing purposes, we're just using the default API key
        # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
        # instead of `r.recognize_google(audio)`
        result1 = "Google Speech Recognition thinks you said " + r.recognize_google(audio)

    except sr.UnknownValueError:
        result1 = "Google Speech Recognition could not understand audio"
    except sr.RequestError as e:
        result1 = "Could not request results from Google Speech Recognition service; {0}".format(e)

    # recognize speech using Google Cloud Speech
    GOOGLE_CLOUD_SPEECH_CREDENTIALS = path.join(path.dirname(path.realpath(__file__)), "credential.json")
    try:
        result2 = "Google Cloud Speech thinks you said " + r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS)
    except sr.UnknownValueError:
        result2 = "Google Cloud Speech could not understand audio"
    except sr.RequestError as e:
        result2 = "Could not request results from Google Cloud Speech service; {0}".format(e)

    return result, result1, result2

Logcat file

2020-06-12 12:57:58.740 20669-20669/? I/e.pythontestin: Late-enabling -Xcheck:jni
2020-06-12 12:57:58.793 20669-20669/? E/e.pythontestin: Unknown bits set in runtime_flags: 0x8000
2020-06-12 12:57:58.796 20669-20669/? I/e.pythontestin: Reinit property: dalvik.vm.checkjni= false
2020-06-12 12:57:58.829 20669-20669/? E/libc: Access denied finding property "runtime.mmitest.isrunning"
2020-06-12 12:57:58.836 20669-20669/? D/ActivityThread: Attach thread to application
2020-06-12 12:57:58.938 20669-20669/com.example.pythontesting I/e.pythontestin: QarthPatchMonintor::Init
2020-06-12 12:57:58.938 20669-20669/com.example.pythontesting I/e.pythontestin: QarthPatchMonintor::StartWatch
2020-06-12 12:57:58.938 20669-20669/com.example.pythontesting I/e.pythontestin: QarthPatchMonintor::WatchPackage: /data/hotpatch/fwkhotpatch/
2020-06-12 12:57:58.938 20669-20669/com.example.pythontesting I/e.pythontestin: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/com.example.pythontesting
2020-06-12 12:57:58.938 20669-20669/com.example.pythontesting I/e.pythontestin: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/all
2020-06-12 12:57:58.938 20669-20669/com.example.pythontesting I/e.pythontestin: QarthPatchMonintor::Run
2020-06-12 12:57:58.938 20669-20705/com.example.pythontesting I/e.pythontestin: QarthPatchMonintor::Reading
2020-06-12 12:57:58.938 20669-20705/com.example.pythontesting I/e.pythontestin: QarthPatchMonintor::CheckNotifyEvent
2020-06-12 12:57:58.938 20669-20705/com.example.pythontesting I/e.pythontestin: QarthPatchMonintor::CheckNotifyEvent before read
2020-06-12 12:57:58.940 20669-20690/com.example.pythontesting I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.pythontesting#10114#256
2020-06-12 12:57:58.940 20669-20690/com.example.pythontesting I/HwApiCacheMangerEx: apicache path=/storage/0748-1500 state=mounted key=com.example.pythontesting#10114#256
2020-06-12 12:57:58.946 20669-20690/com.example.pythontesting I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.pythontesting#10114#0
2020-06-12 12:57:58.946 20669-20690/com.example.pythontesting I/HwApiCacheMangerEx: apicache path=/storage/0748-1500 state=mounted key=com.example.pythontesting#10114#0
2020-06-12 12:57:58.954 20669-20690/com.example.pythontesting I/AwareBitmapCacher: init processName:com.example.pythontesting pid=20669 uid=10114
2020-06-12 12:57:58.958 20669-20707/com.example.pythontesting E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@ca8d525
2020-06-12 12:57:58.959 20669-20707/com.example.pythontesting E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@47236fa
2020-06-12 12:57:59.003 20669-20669/com.example.pythontesting V/ActivityThread: callActivityOnCreate
2020-06-12 12:57:59.037 20669-20669/com.example.pythontesting V/HwWidgetFactory: : successes to get AllImpl object and return....
2020-06-12 12:57:59.059 20669-20669/com.example.pythontesting I/OverScrollerOptimization: start init SmartSlideOverScroller and get the overscroller config
2020-06-12 12:57:59.059 20669-20669/com.example.pythontesting I/OverScrollerOptimization: get the overscroller config
2020-06-12 12:57:59.091 20669-20669/com.example.pythontesting I/AwareAppScheduleManager: post cache drawable res id to aware, resId = 17302090, packagename = com.example.pythontesting, cost time = 11692709
2020-06-12 12:57:59.095 20669-20669/com.example.pythontesting W/e.pythontestin: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2020-06-12 12:57:59.097 20669-20669/com.example.pythontesting W/e.pythontestin: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2020-06-12 12:57:59.448 20669-20669/com.example.pythontesting W/e.pythontestin: Accessing hidden method Landroid/os/Handler;-><init>(Landroid/os/Looper;Landroid/os/Handler$Callback;Z)V (greylist, JNI, allowed)
2020-06-12 12:57:59.448 20669-20669/com.example.pythontesting W/e.pythontestin: Accessing hidden method Landroid/os/Handler;-><init>(Z)V (greylist, JNI, allowed)
2020-06-12 12:57:59.667 20669-20669/com.example.pythontesting W/e.pythontestin: Accessing hidden method Landroid/content/Context;->getSharedPreferences(Ljava/io/File;I)Landroid/content/SharedPreferences; (greylist, JNI, allowed)
2020-06-12 12:57:59.669 20669-20669/com.example.pythontesting W/e.pythontestin: Accessing hidden method Landroid/content/ContextWrapper;->getSharedPreferences(Ljava/io/File;I)Landroid/content/SharedPreferences; (greylist, JNI, allowed)
2020-06-12 12:57:59.698 20669-20669/com.example.pythontesting W/asset: seek out of range: want -20, end=22
2020-06-12 12:57:59.721 20669-20669/com.example.pythontesting W/e.pythontesting: type=1400 audit(0.0:478235): avc: granted { execute } for pid=20669 path="/data/data/com.example.pythontesting/files/chaquopy/AssetFinder/stdlib-armeabi-v7a/_blake2.so" dev="mmcblk0p71" ino=80401 scontext=u:r:untrusted_app:s0:c114,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c114,c256,c512,c768 tclass=file
2020-06-12 12:57:59.729 20669-20669/com.example.pythontesting W/e.pythontesting: type=1400 audit(0.0:478236): avc: granted { execute } for pid=20669 path="/data/data/com.example.pythontesting/files/chaquopy/AssetFinder/stdlib-armeabi-v7a/_sha3.so" dev="mmcblk0p71" ino=80100 scontext=u:r:untrusted_app:s0:c114,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c114,c256,c512,c768 tclass=file
2020-06-12 12:57:59.741 20669-20669/com.example.pythontesting W/e.pythontesting: type=1400 audit(0.0:478237): avc: granted { execute } for pid=20669 path="/data/data/com.example.pythontesting/files/chaquopy/AssetFinder/stdlib-armeabi-v7a/_posixsubprocess.so" dev="mmcblk0p71" ino=80342 scontext=u:r:untrusted_app:s0:c114,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c114,c256,c512,c768 tclass=file
2020-06-12 12:57:59.749 20669-20669/com.example.pythontesting W/e.pythontesting: type=1400 audit(0.0:478238): avc: granted { execute } for pid=20669 path="/data/data/com.example.pythontesting/files/chaquopy/AssetFinder/stdlib-armeabi-v7a/select.so" dev="mmcblk0p71" ino=80532 scontext=u:r:untrusted_app:s0:c114,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c114,c256,c512,c768 tclass=file
2020-06-12 12:57:59.769 20669-20669/com.example.pythontesting W/e.pythontesting: type=1400 audit(0.0:478239): avc: granted { execute } for pid=20669 path="/data/data/com.example.pythontesting/files/chaquopy/AssetFinder/stdlib-armeabi-v7a/_sha512.so" dev="mmcblk0p71" ino=80265 scontext=u:r:untrusted_app:s0:c114,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c114,c256,c512,c768 tclass=file
2020-06-12 12:58:00.065 20669-20669/com.example.pythontesting D/AndroidRuntime: Shutting down VM
2020-06-12 12:58:00.066 20669-20669/com.example.pythontesting I/QarthLog: [PatchStore] createDisableExceptionQarthFile
2020-06-12 12:58:00.066 20669-20669/com.example.pythontesting I/QarthLog: [PatchStore] create disable file for com.example.pythontesting uid is 10114

    --------- beginning of crash
2020-06-12 12:58:00.068 20669-20669/com.example.pythontesting E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.pythontesting, PID: 20669
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pythontesting/com.example.pythontesting.MainActivity}: com.chaquo.python.PyException: OSError: FLAC conversion utility not available - consider installing the FLAC command line application by running `apt-get install flac` or your operating system's equivalent
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3961)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:213)
        at android.app.ActivityThread.main(ActivityThread.java:8178)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
     Caused by: com.chaquo.python.PyException: OSError: FLAC conversion utility not available - consider installing the FLAC command line application by running `apt-get install flac` or your operating system's equivalent
        at <python>.speech_recognition.get_flac_converter(__init__.py:1196)
        at <python>.speech_recognition.get_flac_data(__init__.py:445)
        at <python>.speech_recognition.recognize_google(__init__.py:826)
        at <python>.audio.converter(audio.py:32)
        at <python>.chaquopy_java.call(chaquopy_java.pyx:281)
        at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:253)
        at com.chaquo.python.PyObject.callAttrThrows(Native Method)
        at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
        at com.example.pythontesting.MainActivity.onCreate(MainActivity.java:27)
        at android.app.Activity.performCreate(Activity.java:8086)
        at android.app.Activity.performCreate(Activity.java:8074)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3755)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3961) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:213) 
        at android.app.ActivityThread.main(ActivityThread.java:8178) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) 
2020-06-12 12:58:00.086 20669-20669/? I/Process: Sending signal. PID: 20669 SIG: 9

Please help it would me very helpful

mhsmith commented 4 years ago

Ah, I see, it's trying to convert the audio to FLAC format in order to use the Google speech recognition API. The speech_recognition package includes FLAC converters for Windows, Mac and Linux, but not for Android.

We would have to provide an Android build of the converter. Unfortunately we don't have time to work on this at the moment, but if anyone else needs it, please add a thumbs up at the top of this page.

Abhi55Y commented 4 years ago

Please Let me know if you have the solution..Thank you

mhsmith commented 4 years ago

Let's leave it open in case anyone else has the same problem.

mhsmith commented 3 years ago

Unfortunately newer versions of Android are making it increasingly difficult for apps to include executable files such as the FLAC converter (#605), so we won't be able to support this at the moment.

muthuruban commented 2 years ago

Please Let me know if you have the solution..Thank you

Myself too getting same error in speech recognition while using through kivy in android

hossein4214 commented 1 year ago

Let's leave it open in case anyone else has the same problem.

I am getting same Error in speech recognition in android studio :( Any Help ?