congnitive service speech recognizes nothing

Xinhwang 1 Reputation point
2021-11-23T10:54:31.047+00:00

I am learning Azure cognitive service speech with the environment of VS 2019 and xamarin C# for Android app. I have got the subscription key. However, the speech engine does not recognize anything whatever the language is English, German, .... The followings are my script:
var config = SpeechConfig.FromSubscription(Constants.CognitiveServicesApiKey, Constants.CognitiveServicesRegion);
config.SpeechRecognitionLanguage ="en-US";
var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
recognizer = new SpeechRecognizer(config, audioConfig);
recognizer.Recognized += (obj, args) =>
{
UpdateTranscription(args.Result.Text);
};

I have validated the subscription key through Powershell command. The key is correct. By the way, I also implemented IMicrophoneService in for Android platform as following:
[assembly: Dependency(typeof(AndroidMicrophoneService))]
namespace SpeechAssisTest.Droid.Services
{
public class AndroidMicrophoneService : IMicrophoneService
{
public const int RecordAudioPermissionCode = 1;
private TaskCompletionSource<bool> tcsPermissions;
string[] permissions = new string[] { Manifest.Permission.RecordAudio };
public Task<bool> GetPermissionAsync()
{
tcsPermissions = new TaskCompletionSource<bool>();
if ((int)Build.VERSION.SdkInt < 23)
{
tcsPermissions.TrySetResult(true);
}
else
{
var currentActivity = MainActivity.Instance;
if (ActivityCompat.CheckSelfPermission(currentActivity, Manifest.Permission.RecordAudio) != (int)Permission.Granted)
{
RequestMicPermissions();
}
else
{
tcsPermissions.TrySetResult(true);
}
}
return tcsPermissions.Task;
}
public void OnRequestPermissionResult(bool isGranted)
{
tcsPermissions.TrySetResult(isGranted);
}
void RequestMicPermissions()
{
if (ActivityCompat.ShouldShowRequestPermissionRationale(MainActivity.Instance, Manifest.Permission.RecordAudio))
{
Snackbar.Make(MainActivity.Instance.FindViewById(Android.Resource.Id.Content),
"Microphone permissions are required for speech transcription!",
Snackbar.LengthIndefinite)
.SetAction("Ok", v =>
{
((Activity)MainActivity.Instance).RequestPermissions(permissions, RecordAudioPermissionCode);
})
.Show();
}
else
{
ActivityCompat.RequestPermissions((Activity)MainActivity.Instance, permissions, RecordAudioPermissionCode);
}
}
}
}

Does any body have idea what I am wrong? Your any comments or suggestions are more than welcome. Thanks a lot.

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

1 answer

Sort by: Most helpful
  1. Xinhwang 1 Reputation point
    2021-11-23T11:28:39.637+00:00

    I found solution.

    0 comments No comments