Can I do voice-to-text conversion on an actual Android device?

takanori uoi 6 Reputation points
2022-10-31T08:59:13.817+00:00
  1. Write the following code in an Android Studio project with Speech SDK for Java installed. private static String speechKey = System.getenv((my key1));
    private static String speechRegion = System.getenv((my key2)); SpeechConfig speechConfig = SpeechConfig.fromSubscription(speechKey, speechRegion);
    speechConfig.setSpeechRecognitionLanguage("en-US");
  2. Build and create apk file
  3. Run the apk file you created and see the output of logcat, you will get the following error

How can I use the SpeechSDK externally when I am told there is no subscription key?

Process: samples.speech.cognitiveservices.microsoft.com, PID: 9599
java.lang.RuntimeException: Unable to start activity ComponentInfo{samples.speech.cognitiveservices.microsoft.com/samples.speech.cognitiveservices.microsoft.com.MainActivity}: java.lang.NullPointerException: subscriptionKey
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3640)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3797)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2215)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:346)
at android.os.Looper.loop(Looper.java:475)
at android.app.ActivityThread.main(ActivityThread.java:7890)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1009)
Caused by: java.lang.NullPointerException: subscriptionKey
at com.microsoft.cognitiveservices.speech.util.Contracts.throwIfNullOrWhitespace(Unknown Source:27)
at com.microsoft.cognitiveservices.speech.util.Contracts.throwIfIllegalSubscriptionKey(Unknown Source:0)
at com.microsoft.cognitiveservices.speech.SpeechConfig.fromSubscription(Unknown Source:2)
at samples.speech.cognitiveservices.microsoft.com.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:8050)
at android.app.Activity.performCreate(Activity.java:8030)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1330)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3613)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3797) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2215) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:346) 
at android.os.Looper.loop(Looper.java:475) 
at android.app.ActivityThread.main(ActivityThread.java:7890) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1009) 

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,408 questions
{count} votes

1 answer

Sort by: Most helpful
  1. takanori uoi 6 Reputation points
    2022-11-04T02:44:43.61+00:00

    I retried the following
    The error related to the subscription key is gone, but now I am getting a link error. Can you please help me figure this one out?

    Preparation
    Install Azul Zulu OpenJDK
    Install Microsoft Build of OpenJDK
    Install Apache Maven
    Installed Speech SDK Maven
    Install Android Studio Chipmunk 2021.2.1
    Create a Cognitive services multi-service account
    Set the system environment variable SPEECH_KEY to key 1 of the Cognitive services multiservice account.
    Set the system environment variable SPEECH_REGION to japaneast of the Cognitive services multiservice account.
    Create a voice service account.
    Install Cygwin.

    1. Launch AndroidStudio.
    2. Select File->New Project->Phone and Tablet->Empty Activity and press Next
    3. Enter "SpeechQuickstart" in the Name field.
    4. In PackageName, enter samples.speech.cognitiveservices.microsoft.com
    5. Select any directory in Save location.
    6. Select java in Language.
    7. Under Minimum API lvel, select API 23.
    8. Press "Finish
      9.Select File->Project Structure->Dependncies->app
      10.Select +->Library dependency
      11.Enter com.microsoft.cognitiveservices.speech:client-sdk in step1 and press Search
    9. com.microsoft.cognitiveservices.speech will appear and press OK.
      13.Press OK to close Project Structure.
    10. Press File->Sync Project With Gradle Files
    11. Right click on SpeechQuickStart in the Project window of AndroidStudio
      16.New->File to generate pom.xml
    12. Write the following contents in pom.xml <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.microsoft.cognitiveservices.speech.samples</groupId>
      <artifactId>quickstart-eclipse</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <build>
      <sourceDirectory>src</sourceDirectory>
      <plugins>
      <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.7.0</version>
      <configuration>
      <source>1.8</source>
      <target>1.8</target>
      </configuration>
      </plugin>
      </plugins>
      </build>
      <repositories>
      <repository>
      <id>maven-cognitiveservices-speech</id>
      <name>Microsoft Cognitive Services Speech Maven Repository</name>
      <url>https://azureai.azureedge.net/maven/</url>
      </repository>
      </repositories>
      <dependencies>
      <dependency>
      <groupId>com.microsoft.cognitiveservices.speech</groupId>
      <artifactId>client-sdk</artifactId>
      <version>1.24.1</version>
      </dependency>
      </dependencies>
      </project>
    13. Start Cygwin and navigate to the location where pom.xml is located.
    14. Run mvn clean dependency:copy-dependencies
    15. Add the following to MainActivity.java import com.microsoft.cognitiveservices.speech.*;
      import com.microsoft.cognitiveservices.speech.audio.AudioConfig; public class MainActivity extends AppCompatActivity {
      private static String speechKey = System.getenv("SPEECH_KEY");  
      private static String speechRegion = System.getenv("SPEECH_REGION");  
      
      @Override  
      protected void onCreate(Bundle savedInstanceState) {  
          super.onCreate(savedInstanceState);  
          setContentView(R.layout.activity_main);  
      
          SpeechConfig speechConfig = SpeechConfig.fromSubscription(speechKey, speechRegion);  
      }  
      
      }

    error message

    FATAL EXCEPTION: main
    Process: samples.speech.cognitiveservices.microsoft.com, PID: 4132
    java.lang.UnsatisfiedLinkError: No implementation found for void com.microsoft.cognitiveservices.speech.SpeechConfig.setTempDirectory(java.lang.String) (tried Java_com_microsoft_cognitiveservices_speech_SpeechConfig_setTempDirectory and Java_com_microsoft_cognitiveservices_speech_SpeechConfig_setTempDirectory__Ljava_lang_String_2)
    at com.microsoft.cognitiveservices.speech.SpeechConfig.setTempDirectory(Native Method)
    at com.microsoft.cognitiveservices.speech.SpeechConfig.<clinit>(Unknown Source:55)
    at com.microsoft.cognitiveservices.speech.SpeechConfig.fromSubscription(Unknown Source:0)
    at samples.speech.cognitiveservices.microsoft.com.MainActivity.onCreate(MainActivity.java:18)
    at android.app.Activity.performCreate(Activity.java:8051)
    at android.app.Activity.performCreate(Activity.java:8031)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7839)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

    0 comments No comments