Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not initialize class com.microsoft.cognitiveservices.speech.SpeechConfig #2340

Closed
yangman92 opened this issue Apr 14, 2024 · 7 comments
Assignees
Labels
in-review In review pending close Closed soon without new activity

Comments

@yangman92
Copy link

yangman92 commented Apr 14, 2024

Install the Speech SDK
Configure RHEL/CentOS 7
All the steps above the two links I've done and I was seeking the same issues on github all of them i've been try to but all of them didn't work on me.

I've been trying to solve this problem for almost 2 days.
On my local server it worked but It didn't work on centos 7 server.
Could you please tell me which step i was doing wrong.
Tanks a lot.

I attacked files below.

system: CentOS 7.9.2009 x86_64(Py3.7.9)
error:

  • java.lang.NoClassDefFoundError: Could not initialize class com.microsoft.cognitiveservices.speech.SpeechConfig
  • java.lang.UnsatisfiedLinkError: com.microsoft.cognitiveservices.speech.SpeechConfig.setTempDirectory(Ljava/lang/String;)V
@yangman92
Copy link
Author

step: Configure RHEL/CentOS 7
1
2
3
4
5
6
7
8
9
10

@yangman92
Copy link
Author

step:Install the Speech SDK11

@pankopon
Copy link
Contributor

@yangman92 Your screenshots show errors while trying to build gcc 7.5.0 and runtimes, therefore newer C/C++ runtime libraries required by the Speech SDK were not installed. Looks like you may have already tried to run a build before the screenshots, so it's best to start anew with a clean build. I just verified that instructions in https://learn.microsoft.com/azure/ai-services/speech-service/how-to-configure-rhel-centos-7#cc-compiler-and-runtime-libraries still work on an up-to-date CentOS 7.9.2009 system. Please do not run any commands blindly - check and verify that they complete successfully, otherwise investigate why they failed.

For Java on CentOS 7, see #1769 for an earlier similar question. (Regarding the Speech SDK version used in the example, note that the current latest is 1.37.0.)

Please note that CentOS 7 will reach end of life on June 30, 2024: https://www.redhat.com/en/topics/linux/centos-linux-eol
The Speech SDK support for it will be dropped shortly after.

@pankopon pankopon self-assigned this Apr 15, 2024
@pankopon pankopon added in-review In review pending close Closed soon without new activity labels Apr 15, 2024
@yangman92
Copy link
Author

yangman92 commented Apr 16, 2024

@pankopon Hi. This time I am sure that I correctly done the 2 steps.

# Build GCC 7.5.0 and runtimes and install them under /usr/local
curl https://ftp.gnu.org/gnu/gcc/gcc-7.5.0/gcc-7.5.0.tar.gz -O
tar -xf gcc-7.5.0.tar.gz
mkdir gcc-7.5.0-build && cd gcc-7.5.0-build
../gcc-7.5.0/configure --enable-languages=c,c++ --disable-bootstrap --disable-multilib --prefix=/usr/local
make -j$(nproc)
sudo make install-strip

These commands were executed successfully. The info was so long to print.
But it still did not work.
I don't know what I can do else.
All the same issues I tried to understand but I am still confusing.

1713272011079

1713272915666

I can provide more information you want to see.

@pankopon
Copy link
Contributor

pankopon commented Apr 16, 2024

@yangman92 Here's a command-line example from scratch, presuming you have all dependencies already in place.

Verify that the new compiler (and therefore also the updated C/C++ runtime libraries) is indeed installed:

# which gcc
/usr/local/bin/gcc
# gcc --version
gcc (GCC) 7.5.0

Clone and prepare the Speech SDK sample repository:

# git clone https://github.com/Azure-Samples/cognitive-services-speech-sdk
# cd cognitive-services-speech-sdk/samples/java/jre/console/
# sed -i 's/1\.34\.0/1.37.0/g' pom.xml
# git diff
diff --git a/samples/java/jre/console/pom.xml b/samples/java/jre/console/pom.xml
index 56059d2..de8de3a 100644
--- a/samples/java/jre/console/pom.xml
+++ b/samples/java/jre/console/pom.xml
@@ -56,7 +56,7 @@
     <dependency>
       <groupId>com.microsoft.cognitiveservices.speech</groupId>
       <artifactId>client-sdk</artifactId>
-      <version>1.34.0</version>
+      <version>1.37.0</version>
     </dependency>
     <dependency>
       <groupId>jakarta.json</groupId>

Try for example the case with wav file input.
Edit the source file src/com/microsoft/cognitiveservices/speech/samples/console/SpeechRecognitionSamples.java and find continuousRecognitionWithFileAsync() in that file and replace "Your..." strings with your subscription key, service region, and some wav file path.

In the following, mvn was downloaded from https://maven.apache.org/download.cgi (apache-maven-3.9.6-bin.zip).
(CentOS 7 has only a very old version of mvn, like many other programs.)
Extract the package under /opt and add /opt/apache-maven-3.9.6/bin to PATH like

# export PATH=/opt/apache-maven-3.9.6/bin:$PATH
# mvn --version
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /opt/apache-maven-3.9.6
Java version: 1.8.0_402, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.402.b06-1.el7_9.x86_64/jre

You can use Java 8 or newer, but make sure both java and javac have the same version and you don't have multiple versions conflicting with each other:

# yum list installed | grep jdk
copy-jdk-configs.noarch                 3.3-11.el7_9                   @updates
java-1.8.0-openjdk.x86_64               1:1.8.0.402.b06-1.el7_9        @updates
java-1.8.0-openjdk-devel.x86_64         1:1.8.0.402.b06-1.el7_9        @updates
java-1.8.0-openjdk-headless.x86_64      1:1.8.0.402.b06-1.el7_9        @updates

# java -version
openjdk version "1.8.0_402"
OpenJDK Runtime Environment (build 1.8.0_402-b06)
OpenJDK 64-Bit Server VM (build 25.402-b06, mixed mode)

# javac -version
javac 1.8.0_402

Now build, verify that the correct Speech SDK version is used, and run the sample:

# mvn clean package
...
[INFO] BUILD SUCCESS

# mvn dependency:tree
...
[INFO] SpeechSDKDemo:SpeechSDKDemo:jar:0.0.1-SNAPSHOT
[INFO] +- com.microsoft.cognitiveservices.speech:client-sdk:jar:1.37.0:compile

# export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
# java -jar ./target/SpeechSDKDemo-0.0.1-SNAPSHOT-jar-with-dependencies.jar
 1. Speech recognition with microphone input.
 2. Speech recognition with microphone input and detailed recognition results
 3. Speech recognition in the specified language.
 4. Speech recognition using customized model.
 5. Speech continuous recognition using events with file.
...
Your choice (0: Stop): 5

    Session started event.

RECOGNIZING: Text=what's the weather
RECOGNIZING: Text=what's the weather like
RECOGNIZED: Text=What's the weather like?
CANCELED: Reason=EndOfStream

    Session stopped event.

If this really doesn't work for you then it seems your CentOS 7 installation/environment is somehow different from what it should be.

@yangman92
Copy link
Author

It is not easy to deploy on a centos system.
You need to do 3 steps.
Some issues did not clearly show what the problem is or less steps.

Install the Speech SDK
Configure RHEL/CentOS 7
Download and extract the Speech SDK

My friend helped me today to deploy. It worked now.

@jpalvarezl
Copy link
Contributor

Thank you for the update. I will close the issue now since it seems like the discussion reached its conclusion. Feel free to open this issue again if there is some more questions related to this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-review In review pending close Closed soon without new activity
Projects
None yet
Development

No branches or pull requests

3 participants