Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
MIT License
2.69k stars 1.79k forks source link

0x15 (SPXERR_MIC_ERROR) Exception with an error code: 0x15 (SPXERR_MIC_ERROR) #2438

Open pengcheng933 opened 1 week ago

pengcheng933 commented 1 week ago

IN ORDER TO ASSIST YOU, PLEASE PROVIDE THE FOLLOWING:

Describe the bug I configured the key, instantiated the object, and got an error when I started speech-to-text. But I found that I can convert speech to text, I just can't call the microphone for real time speech to text, I checked the microphone permissions, and they are there! Note that I am hybrid app. i am calling IOS method in webview

To Reproduce

Steps to reproduce the behavior:

  1. Create a hybrid app and copy the code above
  2. Triggering this method will report an error

Version of the Cognitive Services Speech SDK

1.38.0

Platform, Operating System, and Programming Language

Additional context Speech recognition was canceled: 0x15 (SPXERR_MIC_ERROR) Exception with an error code: 0x15 (SPXERR_MIC_ERROR) [CALL STACK BEGIN]

3 MicrosoftCognitiveServicesSpeech 0x0000000102fbbb44 GetModuleObject + 1701508 4 MicrosoftCognitiveServicesSpeech 0x0000000102f0dd24 GetModuleObject + 989284 5 MicrosoftCognitiveServicesSpeech 0x0000000102f1fe64 GetModuleObject + 1063332 6 MicrosoftCognitiveServicesSpeech 0x0000000102f18eec GetModuleObject + 1034796 7 MicrosoftCognitiveServicesSpeech 0x0000000102f18580 GetModuleObject + 1032384 8 MicrosoftCognitiveServicesSpeech 0x0000000102f153e0 GetModuleObject + 1019680 9 MicrosoftCognitiveServicesSpeech 0x0000000102edd6d4 GetModuleObject + 791060 10 MicrosoftCognitiveServicesSpeech 0x0000000102eda2b4 GetModuleObject + 777716 11 MicrosoftCognitiveServicesSpeech 0x0000000102e2b978 GetModuleObject + 62648 12 MicrosoftCognitiveServicesSpeech 0x0000000102e29018 GetModuleObject + 52056 13 MicrosoftCognitiveServicesSpeech 0x0000000102e286b0 GetModuleObject + 49648 14 MicrosoftCognitiveServicesSpeech 0x0000000102e48684 GetModuleObject + 180676 15 MicrosoftCognitiveServicesSpeech 0x0000000102e444b4 GetModuleObject + 163828 16 MicrosoftCognitiveServicesSpeech 0x0000000102f6ea04 GetModuleObject + 1385796 17 MicrosoftCognitiveServicesSpeech 0x0000000102f6e990 GetModuleObject + 1385680 18 MicrosoftCognitiveServicesSpeech 0x0000000102f70830 GetModuleObject + 1393520 19 MicrosoftCognitiveServicesSpeech 0x0000000102f6eb68 GetModuleObject + 1386152 [CALL STACK END]

SessionId: e73d165980634f3ab66244902f3f1cfd. Did you pass the correct key/region combination? Error: Time:Mon Jun 24 17:04:42 2024

pengcheng933 commented 1 week ago

I copied the official example, no error can be normal to text, I am a hybrid app, in the web view to call the error

pengcheng933 commented 3 days ago

Solved, the following code needs to be added


audioEngine = [[AVAudioEngine alloc] init];
    audioData = [[NSMutableData alloc] init];

    AVAudioFormat *outputFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatInt16
                                                                   sampleRate:16000
                                                                     channels:1
                                                                  interleaved:NO];
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *error = nil;
    [audioSession setCategory:AVAudioSessionCategoryRecord mode:AVAudioSessionModeMeasurement options:AVAudioSessionCategoryOptionDuckOthers error:&error];
    [audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];
    inputNode = audioEngine.inputNode;
    AVAudioFormat *inputFormat = [inputNode outputFormatForBus:0];
    AVAudioConverter *converter = [[AVAudioConverter alloc] initFromFormat:inputFormat toFormat:outputFormat];