I would like to know how I could use PocketSphinx library in my Xamarin.Android project.
I tried to make a wrapper of pocketsphinx-android-5prealpha-nolib.jar without success. Anyway, I saw on a topic on this forum that it wasn't the good way to do it.
I also tried to use native libraries (libpocketsphinx_jni.so) but I haven't found a way to use it. My project can build and run but I don't know how to access and use the lib.so (even with [DLLImport ("pocketsphinx_jni.so")] ).
Is it possible to get this kind of project for Xamarin.Android https://github.com/cmusphinx/pocketsphinx-wp-demo?
Do I have to code in C or C++ or can I simply use the library from my project (reference)?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We provide C# bindings, you just need to compile pocketsphinx for android. You can import pocketsphinx_jni.so too, but you can also compile pocketsphinx for android without jni with cmake and NDK.
I saw that this dll is created by the makefile. How can I get this? Am I supposed to build my own cmake Makefile from yours? I never used Cmake before :(
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I finally found a way to generate the C# binding. I tried to follow the tuto on https://github.com/cmusphinx/pocketsphinx-android but it seems to be only written for Android Studio user. So I downloaded it but I never found how to make it workn :p...
So, I have installed swig, cmake and gradle. I put the three projects in the same root folder (sphinxbase, pocketsphinx and pocketsphinx-android). I changed the build.gradle as you told me to do ( java -> csharp).
I had troubles executing the command "gradle build" so I created the folder '/generated-src\cpp' and 'generated-src\csharp' manually. I finally executed the two following commands in the pocketsphinx-android folder:
Am I doing something wrong? I am a student in IT and I never heard/used gradle before. Should I try with Android Studio instead? Is the "Unsupported major.minor version 52.0" error caused by the java version I use?
C:\Users...\pocketsphinx-android>java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Last edit: Bruno Moureau 2017-03-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do I have to use Android Studio to run the build.gradle file?
No, you can invoke gradle from command line
java.lang.UnsupportedClassVersionError: com/android/build/gradle/LibraryPlugin : Unsupported major.minor version 52.0
This error means studio runs with Java 1.7, not 1.8, you need to check if you have older java also installed and make sure you have proper JAVA_HOME environment variable.
I haven't changed the file excepted java -> csharp :
I guess I had to put the parameters in the two tasks : 'SphinxBase' in the first and 'PocketSphinx' in the second.
I succeeded to run the build.gradle! Thanks again! :)
Now I have some other issues and I don't know how to solve them. Here's the output :
C:\Users\...\pocketsphinx-android>gradle build
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
at build_8cqm3r2p0agiegw77ulywtfkv.run(C:\Users\...\pocketsphinx-android\build.gradle:37)
The JavaCompile.setDependencyCacheDir() method has been deprecated and is scheduled to be removed in Gradle 4.0.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
:mkdir
:swigPs
:swigSb
:preBuild
:preDebugBuild
:checkDebugManifest
:prepareDebugDependencies
:compileDebugAidl UP-TO-DATE
:compileLint UP-TO-DATE
:copyDebugLint NO-SOURCE
:mergeDebugShaders UP-TO-DATE
:compileDebugShaders UP-TO-DATE
:generateDebugAssets UP-TO-DATE
:mergeDebugAssets UP-TO-DATE
:mergeDebugProguardFiles UP-TO-DATE
:packageDebugRenderscript NO-SOURCE
:compileDebugRenderscript UP-TO-DATE
:generateDebugResValues UP-TO-DATE
:generateDebugResources UP-TO-DATE
:packageDebugResources UP-TO-DATE
:processDebugManifest UP-TO-DATE
:generateDebugBuildConfig UP-TO-DATE
:processDebugResources UP-TO-DATE
:generateDebugSources UP-TO-DATE
:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:compileDebugJavaWithJavac
:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\RecognitionListener.java:33: error: cannot find symbol
import edu.cmu.pocketsphinx.Hypothesis;
^
symbol: class Hypothesis
location: package edu.cmu.pocketsphinx
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\RecognitionListener.java:51: error: cannot find symbol
public void onPartialResult(Hypothesis hypothesis);
^
symbol: class Hypothesis
location: interface RecognitionListener
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\RecognitionListener.java:56: error: cannot find symbol
public void onResult(Hypothesis hypothesis);
^
symbol: class Hypothesis
location: interface RecognitionListener
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizer.java:58: error: cannot find symbol
private final Decoder decoder;
^
symbol: class Decoder
location: class SpeechRecognizer
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizer.java:78: error: cannot find symbol
protected SpeechRecognizer(Config config) throws IOException {
^
symbol: class Config
location: class SpeechRecognizer
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizer.java:200: error: cannot find symbol
public Decoder getDecoder() {
^
symbol: class Decoder
location: class SpeechRecognizer
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizer.java:220: error: cannot find symbol
public void addFsgSearch(String searchName, FsgModel fsgModel) {
^
symbol: class FsgModel
location: class SpeechRecognizer
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizer.java:414: error: cannot find symbol
protected final Hypothesis hypothesis;
^
symbol: class Hypothesis
location: class SpeechRecognizer.ResultEvent
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizer.java:417: error: cannot find symbol
ResultEvent(Hypothesis hypothesis, boolean finalResult) {
^
symbol: class Hypothesis
location: class SpeechRecognizer.ResultEvent
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizerSetup.java:33: error: cannot find symbol
import static edu.cmu.pocketsphinx.Decoder.defaultConfig;
^
symbol: class Decoder
location: package edu.cmu.pocketsphinx
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizerSetup.java:33: error: static import only from classes and interfaces
import static edu.cmu.pocketsphinx.Decoder.defaultConfig;
^
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizerSetup.java:34: error: cannot find symbol
import static edu.cmu.pocketsphinx.Decoder.fileConfig;
^
symbol: class Decoder
location: package edu.cmu.pocketsphinx
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizerSetup.java:34: error: static import only from classes and interfaces
import static edu.cmu.pocketsphinx.Decoder.fileConfig;
^
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizerSetup.java:49: error: cannot find symbol
private final Config config;
^
symbol: class Config
location: class SpeechRecognizerSetup
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizerSetup.java:69: error: cannot find symbol
private SpeechRecognizerSetup(Config config) {
^
symbol: class Config
location: class SpeechRecognizerSetup
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizer.java:79: error: cannot find symbol
decoder = new Decoder(config);
^
symbol: class Decoder
location: class SpeechRecognizer
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizer.java:173: error: cannot find symbol
final Hypothesis hypothesis = decoder.hyp();
^
symbol: class Hypothesis
location: class SpeechRecognizer
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizer.java:365: error: cannot find symbol
final Hypothesis hypothesis = decoder.hyp();
^
symbol: class Hypothesis
location: class SpeechRecognizer.RecognizerThread
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizerSetup.java:55: error: cannot find symbol
return new SpeechRecognizerSetup(defaultConfig());
^
symbol: method defaultConfig()
location: class SpeechRecognizerSetup
C:\Users\...\pocketsphinx-android\src\main\java\edu\cmu\pocketsphinx\SpeechRecognizerSetup.java:66: error: cannot find symbol
return new SpeechRecognizerSetup(fileConfig(configFile.getPath()));
^
symbol: method fileConfig(String)
location: class SpeechRecognizerSetup
20 errors
:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.524 secs
What am I supposed to do?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, thanks it worked since I deleted the java folder from \build\main\ and the reference in the buld.gradle. I built once again and got :
------------------------------------------------------------
Root project
------------------------------------------------------------
classpath
No dependencies
BUILD SUCCESSFUL
Total time: 1.301 secs
I was happy when I saw 'BUILD SUCCESSFUL' until I noticed that all the files hadn't been all generated (armeabi-v7a...) ! So, I decided to delete the folder \build and to run the gradle build command again.
I got this following error now :
:generateJsonModelDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateJsonModelDebug'.
> Build command failed.
Error while executing 'C:\Program Files (x86)\Android\android-sdk\cmake\bin\cmake.exe' with arguments {-HC:\Users\...\pocketsphinx-android -BC:\Users\...\pocketsphinx-android\.externalNativeBuild\cmake\debug\armeabi-v7a -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi-v7a -DANDROID_NDK=C:\ProgramData\Microsoft\AndroidNDK\android-ndk-r11c -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\...\pocketsphinx-android\build\intermediates\cmake\debug\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:\Program Files (x86)\Android\android-sdk\cmake\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\Program Files (x86)\Android\android-sdk\cmake\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=14}
CMake Error: Could not create named generator Android Gradle - Ninja
Here is the full output:
C:\Users\...\pocketsphinx-android>gradle build
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
at build_8cqm3r2p0agiegw77ulywtfkv.run(C:\Users\...\pocketsphinx-android\build.gradle:37)
The JavaCompile.setDependencyCacheDir() method has been deprecated and is scheduled to be removed in Gradle 4.0.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
:mkdir
:swigPs
:swigSb
:preBuild
:preDebugBuild
:checkDebugManifest
:prepareDebugDependencies
:compileDebugAidl
:compileLint
:copyDebugLint NO-SOURCE
:mergeDebugShaders
:compileDebugShaders
:generateDebugAssets
:mergeDebugAssets
:mergeDebugProguardFiles UP-TO-DATE
:packageDebugRenderscript NO-SOURCE
:compileDebugRenderscript
:generateDebugResValues
:generateDebugResources
:packageDebugResources
:processDebugManifest
:generateDebugBuildConfig
:processDebugResources
:generateDebugSources
:incrementalDebugJavaCompilationSafeguard
:compileDebugJavaWithJavac
:processDebugJavaRes NO-SOURCE
:transformResourcesWithMergeJavaResForDebug
:transformClassesAndResourcesWithSyncLibJarsForDebug
:generateJsonModelDebug
CMake Error: Could not create named generator Android Gradle - Ninja
Generators
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 8 2005 [arch] = Generates Visual Studio 2005 project files.
Optional [arch] can be "Win64".
Visual Studio 7 .NET 2003 = Deprecated. Generates Visual Studio .NET
2003 project files.
Borland Makefiles = Generates Borland makefiles.
NMake Makefiles = Generates NMake makefiles.
NMake Makefiles JOM = Generates JOM makefiles.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
MSYS Makefiles = Generates MSYS makefiles.
MinGW Makefiles = Generates a make file for use with
mingw32-make.
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles JOM
= Generates CodeBlocks project files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - MinGW Makefiles = Generates CodeLite project files.
CodeLite - NMake Makefiles = Generates CodeLite project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Sublime Text 2 - MinGW Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - NMake Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
Kate - MinGW Makefiles = Generates Kate project files.
Kate - NMake Makefiles = Generates Kate project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
CMake Error: Could not create named generator Android Gradle - Ninja
Generators
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 8 2005 [arch] = Generates Visual Studio 2005 project files.
Optional [arch] can be "Win64".
Visual Studio 7 .NET 2003 = Deprecated. Generates Visual Studio .NET
2003 project files.
Borland Makefiles = Generates Borland makefiles.
NMake Makefiles = Generates NMake makefiles.
NMake Makefiles JOM = Generates JOM makefiles.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
MSYS Makefiles = Generates MSYS makefiles.
MinGW Makefiles = Generates a make file for use with
mingw32-make.
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles JOM
= Generates CodeBlocks project files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - MinGW Makefiles = Generates CodeLite project files.
CodeLite - NMake Makefiles = Generates CodeLite project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Sublime Text 2 - MinGW Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - NMake Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
Kate - MinGW Makefiles = Generates Kate project files.
Kate - NMake Makefiles = Generates Kate project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
CMake Error: Could not create named generator Android Gradle - Ninja
Generators
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 8 2005 [arch] = Generates Visual Studio 2005 project files.
Optional [arch] can be "Win64".
Visual Studio 7 .NET 2003 = Deprecated. Generates Visual Studio .NET
2003 project files.
Borland Makefiles = Generates Borland makefiles.
NMake Makefiles = Generates NMake makefiles.
NMake Makefiles JOM = Generates JOM makefiles.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
MSYS Makefiles = Generates MSYS makefiles.
MinGW Makefiles = Generates a make file for use with
mingw32-make.
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles JOM
= Generates CodeBlocks project files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - MinGW Makefiles = Generates CodeLite project files.
CodeLite - NMake Makefiles = Generates CodeLite project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Sublime Text 2 - MinGW Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - NMake Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
Kate - MinGW Makefiles = Generates Kate project files.
Kate - NMake Makefiles = Generates Kate project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
CMake Error: Could not create named generator Android Gradle - Ninja
Generators
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 8 2005 [arch] = Generates Visual Studio 2005 project files.
Optional [arch] can be "Win64".
Visual Studio 7 .NET 2003 = Deprecated. Generates Visual Studio .NET
2003 project files.
Borland Makefiles = Generates Borland makefiles.
NMake Makefiles = Generates NMake makefiles.
NMake Makefiles JOM = Generates JOM makefiles.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
MSYS Makefiles = Generates MSYS makefiles.
MinGW Makefiles = Generates a make file for use with
mingw32-make.
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles JOM
= Generates CodeBlocks project files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - MinGW Makefiles = Generates CodeLite project files.
CodeLite - NMake Makefiles = Generates CodeLite project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Sublime Text 2 - MinGW Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - NMake Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
Kate - MinGW Makefiles = Generates Kate project files.
Kate - NMake Makefiles = Generates Kate project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
:generateJsonModelDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateJsonModelDebug'.
> Build command failed.
Error while executing 'C:\Program Files (x86)\Android\android-sdk\cmake\bin\cmake.exe' with arguments {-HC:\Users\...\pocketsphinx-android -BC:\Users\...\pocketsphinx-android\.externalNativeBuild\cmake\debug\armeabi-v7a -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi-v7a -DANDROID_NDK=C:\ProgramData\Microsoft\AndroidNDK\android-ndk-r11c -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\...\pocketsphinx-android\build\intermediates\cmake\debug\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:\Program Files (x86)\Android\android-sdk\cmake\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\Program Files (x86)\Android\android-sdk\cmake\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=14}
CMake Error: Could not create named generator Android Gradle - Ninja
Generators
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 8 2005 [arch] = Generates Visual Studio 2005 project files.
Optional [arch] can be "Win64".
Visual Studio 7 .NET 2003 = Deprecated. Generates Visual Studio .NET
2003 project files.
Borland Makefiles = Generates Borland makefiles.
NMake Makefiles = Generates NMake makefiles.
NMake Makefiles JOM = Generates JOM makefiles.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
MSYS Makefiles = Generates MSYS makefiles.
MinGW Makefiles = Generates a make file for use with
mingw32-make.
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles JOM
= Generates CodeBlocks project files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - MinGW Makefiles = Generates CodeLite project files.
CodeLite - NMake Makefiles = Generates CodeLite project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Sublime Text 2 - MinGW Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - NMake Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
Kate - MinGW Makefiles = Generates Kate project files.
Kate - NMake Makefiles = Generates Kate project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.614 secs
I tried to install 'ninja' and put the 'ninja.exe' in 'C:\Program Files (x86)\Android\android-sdk\cmake\bin' but the error is still here. Should I check for another version of cmake or ninja to run it?
C:\Users\...\pocketsphinx-android>cmake -version
cmake version 3.8.0-rc2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
I found out what this error said. The cmake version I used doesn't have the name generator 'Android Gradle - Ninja'. So, I used the cmake installed within the SDK of Android Studio (cmake -version to check all the name generator available). I just changed the SDK path in the local.properties file to use the one installed with the right cmake version.
I built the build.gradle file again. Then I got two errors :
config.h and sphinx_config.h missing --> I added ../sphinxbase/include/android parameter in "include directories' in MakeLists.txt.
include <io.h> in (sphinxbase\src\libsphinxbase\util) cmd_ln.h and pio.h --> I tried to replace it by <stdio.h> and it worked. Should I build on Linux env instead?
Finally, the last build worked!
I included all architecture files generated in pocketsphinx-android\build\intermediates\bundles\debug\jni to my Xamarin.Android project. I renamed the libpocketsphinx_jni.so into libpocketsphinxwrap.so. I also changed the buildAction to AndroidNativeLibrary.
I put this sample in the MainActivity.cs :
Config c = Decoder.DefaultConfig();
c.SetString("-hmm", "../../model/en-us/en-us");
c.SetString("-lm", "../../model/en-us/en-us.lm.bin");
c.SetString("-dict", "../../model/en-us/cmudict-en-us.dict");
Decoder d = new Decoder(c);
byte[] data = File.ReadAllBytes("../../Assets/recording/goforward.raw");
d.StartUtt();
d.ProcessRaw(data, data.Length, false, false);
d.EndUtt();
Console.WriteLine("Result is '{0}'", d.Hyp().Hypstr);
foreach (Segment s in d.Seg())
{
Console.WriteLine(s);
}
My assets folder look like this :www.hostingpics.net/viewer.php?id=207454Assets.png
Am I doing it right? Can I use this sample in Xamarin.Android project? I have trouble with File.ReadAllBytes method (System.IO.DirectoryNotFoundException: Could not find a part of the path "/Assets/recording/goforward.raw"). I don't find how to retrieve byte array from AndroidAsset.
Last edit: Bruno Moureau 2017-03-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is not possible to read assets as files, they are only accessible as streams. You can put the files on sdcard for testing. You need to put models on sdcard too otherwise pocketsphinx will not load them.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Nickolay, I'm adding speech recognition to my Android-Unity game. I downloaded and tested pocketsphinx-unity-demo-master on my Android phone, but Decoder.DefaultConfig() in SetupDecoder() seems to throw an exception, and when I run it in in the editor, I got DllNotFoundException: libpocketsphinxwrap.
Is it not supposed to work on Android yet? or do I have to do extra steps? and ultimately can I distribute my game as one APK file (with all the resource files automatically set up for the users)?
Your help will be greatly appreciated!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I created a new folder called SPHINX in my Android device. Then, I put the files manually into it.
var dir = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/SPHINX");
if (!dir.Exists())
create = dir.Mkdirs();
//if (dir.Exists())
// erase = dir.Delete();
Android.OS.Environment.ExternalStorageDirectory.AbsolutePath returns something like "/storage/emulated/0". I put /recording/goforward.raw into the SPHINX folder and retrieved it with :
byte[] data = File.ReadAllBytes("/storage/emulated/0/SPHINX/recording/goforward.raw");
I did the same for -hmm, -lm and -dict.
Now, I will try to find a way to deploy the app with embedded files.
Thanks again!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I would like to know how I could use PocketSphinx library in my Xamarin.Android project.
I tried to make a wrapper of pocketsphinx-android-5prealpha-nolib.jar without success. Anyway, I saw on a topic on this forum that it wasn't the good way to do it.
I also tried to use native libraries (libpocketsphinx_jni.so) but I haven't found a way to use it. My project can build and run but I don't know how to access and use the lib.so (even with [DLLImport ("pocketsphinx_jni.so")] ).
Finally, I followed the tuto on http://cmusphinx.sourceforge.net/wiki/tutorialpocketsphinx. I cloned the repositories of basesphinx and pocketsphinx then built them. I don't know what to do next.
Is it possible to get this kind of project for Xamarin.Android https://github.com/cmusphinx/pocketsphinx-wp-demo?
Do I have to code in C or C++ or can I simply use the library from my project (reference)?
We provide C# bindings, you just need to compile pocketsphinx for android. You can import pocketsphinx_jni.so too, but you can also compile pocketsphinx for android without jni with cmake and NDK.
https://github.com/cmusphinx/pocketsphinx/tree/master/swig/csharp
Generated bindings are here:
https://github.com/cmusphinx/pocketsphinx-unity-demo/tree/master/Assets/Pocketsphinx
Thank you for your answers, Nickolay !
I will look at this tomorrow and give you a feedback.
I don't understand how to use the makefile from https://github.com/cmusphinx/pocketsphinx/tree/master/swig/csharp to build the C# bindings with cmake and NDK...
I'm working on Visual Studio 2015 on Windows 10.
I tried to use the C# bindings from https://github.com/cmusphinx/pocketsphinx-unity-demo/tree/master/Assets/Pocketsphinx
but it seems that I need one more dll (libpocketsphinxwrap) to call :
[global::System.Runtime.InteropServices.DllImport("libpocketsphinxwrap", EntryPoint="CSharp_Decoder_DefaultConfig")].
I saw that this dll is created by the makefile. How can I get this? Am I supposed to build my own cmake Makefile from yours? I never used Cmake before :(
Cmake for android is here:
https://github.com/cmusphinx/pocketsphinx-android/blob/master/CMakeLists.txt
you just need to change the swig options in build.gradle to build c# binding wrappers instead of java binding wrappers.
Hi,
I finally found a way to generate the C# binding. I tried to follow the tuto on https://github.com/cmusphinx/pocketsphinx-android but it seems to be only written for Android Studio user. So I downloaded it but I never found how to make it workn :p...
So, I have installed swig, cmake and gradle. I put the three projects in the same root folder (sphinxbase, pocketsphinx and pocketsphinx-android). I changed the build.gradle as you told me to do ( java -> csharp).
I had troubles executing the command "gradle build" so I created the folder '/generated-src\cpp' and 'generated-src\csharp' manually. I finally executed the two following commands in the pocketsphinx-android folder:
It has created the C# binding in the right directory and two .c file in the cpp directory (pocketsphinx_wrap + sphinxbase_wrap). Unsuccessfully, there is a missing DLL again when I execute the sample of code given here https://github.com/cmusphinx/pocketsphinx/blob/master/swig/csharp/test.cs.
The exception is thrown by the missing DLL called 'PocketSphinx' :
I noticed that the two .c files seems to contains all the implementation of the missing 'PocketSphinx' DLL.
Can you please tell me what to do next?
Compile missing dll with cmake?
Actually, you should have fixed full gradle build first.
Do I have to use Android Studio to run the build.gradle file?
Every time I try to build it, I get the following exception :
I haven't changed the file excepted java -> csharp :
Am I doing something wrong? I am a student in IT and I never heard/used gradle before. Should I try with Android Studio instead? Is the "Unsupported major.minor version 52.0" error caused by the java version I use?
C:\Users...\pocketsphinx-android>java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Last edit: Bruno Moureau 2017-03-10
No, you can invoke gradle from command line
This error means studio runs with Java 1.7, not 1.8, you need to check if you have older java also installed and make sure you have proper JAVA_HOME environment variable.
Swig charp also needs
instead of Java option
"-package", "edu.cmu.pocketsphinx",
You have a good chance to learn new things.
Thank you for your answer.
I changed the build.gradle file :
I guess I had to put the parameters in the two tasks : 'SphinxBase' in the first and 'PocketSphinx' in the second.
I succeeded to run the build.gradle! Thanks again! :)
Now I have some other issues and I don't know how to solve them. Here's the output :
What am I supposed to do?
Delete java sources from the project.
Ok, thanks it worked since I deleted the java folder from \build\main\ and the reference in the buld.gradle. I built once again and got :
I was happy when I saw 'BUILD SUCCESSFUL' until I noticed that all the files hadn't been all generated (armeabi-v7a...) ! So, I decided to delete the folder \build and to run the gradle build command again.
I got this following error now :
Here is the full output:
I tried to install 'ninja' and put the 'ninja.exe' in 'C:\Program Files (x86)\Android\android-sdk\cmake\bin' but the error is still here. Should I check for another version of cmake or ninja to run it?
I tried to use a up-to-date NDK as suggested in another forum but the error persists.
I found out what this error said. The cmake version I used doesn't have the name generator 'Android Gradle - Ninja'. So, I used the cmake installed within the SDK of Android Studio (cmake -version to check all the name generator available). I just changed the SDK path in the local.properties file to use the one installed with the right cmake version.
I built the build.gradle file again. Then I got two errors :
Finally, the last build worked!
I included all architecture files generated in pocketsphinx-android\build\intermediates\bundles\debug\jni to my Xamarin.Android project. I renamed the libpocketsphinx_jni.so into libpocketsphinxwrap.so. I also changed the buildAction to AndroidNativeLibrary.
I put this sample in the MainActivity.cs :
My assets folder look like this :www.hostingpics.net/viewer.php?id=207454Assets.png
Am I doing it right? Can I use this sample in Xamarin.Android project? I have trouble with File.ReadAllBytes method (System.IO.DirectoryNotFoundException: Could not find a part of the path "/Assets/recording/goforward.raw"). I don't find how to retrieve byte array from AndroidAsset.
Last edit: Bruno Moureau 2017-03-16
It is not possible to read assets as files, they are only accessible as streams. You can put the files on sdcard for testing. You need to put models on sdcard too otherwise pocketsphinx will not load them.
Hi Nickolay, I'm adding speech recognition to my Android-Unity game. I downloaded and tested pocketsphinx-unity-demo-master on my Android phone, but Decoder.DefaultConfig() in SetupDecoder() seems to throw an exception, and when I run it in in the editor, I got DllNotFoundException: libpocketsphinxwrap.
Is it not supposed to work on Android yet? or do I have to do extra steps? and ultimately can I distribute my game as one APK file (with all the resource files automatically set up for the users)?
Your help will be greatly appreciated!
Yes
Yes
Yes
It works! Thank you for all, Nickolay! :)
I created a new folder called SPHINX in my Android device. Then, I put the files manually into it.
Android.OS.Environment.ExternalStorageDirectory.AbsolutePath returns something like "/storage/emulated/0". I put /recording/goforward.raw into the SPHINX folder and retrieved it with :
I did the same for -hmm, -lm and -dict.
Now, I will try to find a way to deploy the app with embedded files.
Thanks again!
Ok, congratulations. You have to implement model unpack from network or from assets to the filesystem like in android demo.
I'm going to impelment model loading from stream but it is not there yet.