Skip to content

An integration of Azure Speech Service and Azure OpenAI in Android. This repository demonstrates a pipeline where speech from the microphone is first converted to text using Azure Speech Service. The resulting text is then passed to the Azure OpenAI service, which generates a response to the provided prompt.

Notifications You must be signed in to change notification settings

akashchaudhary-git/android-azure-speech-openai

Repository files navigation

Azure Speech + Azure OpenAI

Replace your key and region required in Mainactivity.java

Quickstart: Recognize speech from a microphone in Java on Android

This sample demonstrates how to recognize speech with Java using the Speech SDK for Android. See the accompanying article on the SDK documentation page which describes how to build this sample from scratch in Android Studio.

Prerequisites

Build the sample

Note: more detailed step-by-step instructions are available here.

  • By building this sample you will download the Microsoft Cognitive Services Speech SDK. By downloading you acknowledge its license, see Speech SDK license agreement.
  • Download the sample code to your development PC.
  • Open this folder as a project in Android Studio.
  • Edit the MainActivity source:
    • Replace the string YourSubscriptionKey with your own subscription key.
    • Replace the string YourServiceRegion with the service region of your subscription. For example, replace with westus if you are using the 30-day free trial subscription.
  • Press Ctrl+F9, or select Build > Make Project.

Run the sample

  • Connect your Android device to your development PC.
  • Press Shift+F10, or select Run > Run 'app'.
  • In the deployment target windows that comes up, pick your Android device.

Note on Android permission handling

Please note that the Speech SDK requires two permissions, i.e., the INTERNET as well as the RECORD_AUDIO permission. As for Android API levels up to 22, requesting the permissions is handled at installation time but from API level 23 users are able to grant/revoke permissions at any time.

Note that this quickstart targets minSdkVersion 21, so you need to add the following code if you want to retarget to minSdkVersion 23 or later:

// Initialize SpeechSDK and request required permissions.
try {
    // a unique number within the application to allow
    // correlating permission request responses with the request.
    int permissionRequestId = 5;

    // Request permissions needed for speech recognition
    ActivityCompat.requestPermissions(MainActivity.this, new String[]{RECORD_AUDIO, INTERNET}, permissionRequestId);
}
catch (Exception ex) {
    Log.e("SpeechSDK", "could not init sdk, " + ex.toString());
    recognizedTextView.setText("Could not initialize: " + ex.toString());
}

References

About

An integration of Azure Speech Service and Azure OpenAI in Android. This repository demonstrates a pipeline where speech from the microphone is first converted to text using Azure Speech Service. The resulting text is then passed to the Azure OpenAI service, which generates a response to the provided prompt.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages