Azure-Samples / cognitive-services-speech-sdk

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

ErrorDetails=Runtime error: Failed to initialize platform (azure-c-shared). Error: 2176 SessionId: a87b07d1bc444cd7881c4a9b0d918c0b #2410

Closed xmpppargat closed 1 month ago

xmpppargat commented 3 months ago

Hi i am trying to integrate (cognitive-services-speech-sdk) speech to text in jigasi but facing issue. I am passing audio input stream, tested with microphone its working.

@Override
    public void sendRequest(TranscriptionRequest request)
     {
        if (ended) 
        {
            throw new IllegalStateException("Cannot send request after session has ended");
        }
        try
         {
              byte[] byteArr = request.getAudio();
             SpeechConfig speechConfig = SpeechConfig.fromSubscription("speech_ky", "speech_region"); -> using correct values
             speechConfig.setSpeechRecognitionLanguage("en-US");
              PullAudioInputStreamCallback audioStreamCallback = new BinaryAudioStreamReader(byteArr);
              AudioConfig audioConfig = AudioConfig.fromStreamInput(audioStreamCallback);
              SpeechRecognizer speechRecognizer = new SpeechRecognizer(speechConfig, audioConfig);
              Future<SpeechRecognitionResult> task = speechRecognizer.recognizeOnceAsync();
              SpeechRecognitionResult speechRecognitionResult = task.get();
              Instant timeRequestReceived = Instant.now();
             if (speechRecognitionResult.getReason() == ResultReason.RecognizedSpeech) 
             {
            System.out.println("RECOGNIZED: Text=" + speechRecognitionResult.getText());
               String transcription = speechRecognitionResult.getText().trim();
                for (TranscriptionListener l : listeners) 
                {
                    l.notify(new TranscriptionResult(
                            null,
                            UUID.randomUUID(),
                            timeRequestReceived,
                            false,
                            "en-US",
                            0.0,
                            new TranscriptionAlternative(transcription)));
                }
        }
        else if (speechRecognitionResult.getReason() == ResultReason.NoMatch) 
        {
            System.out.println("NOMATCH: Speech could not be recognized.");
        }
        else if (speechRecognitionResult.getReason() == ResultReason.Canceled) 
        {
            CancellationDetails cancellation = CancellationDetails.fromResult(speechRecognitionResult);
            System.out.println("CANCELED: Reason=" + cancellation.getReason());

            if (cancellation.getReason() == CancellationReason.Error) 
            {
                System.out.println("CANCELED: ErrorCode=" + cancellation.getErrorCode());
                System.out.println("CANCELED: ErrorDetails=" + cancellation.getErrorDetails());
                System.out.println("CANCELED: Did you set the speech resource key and region values?");
            }
        }
            speechRecognizer.close();

        } 
        catch (Exception e)
        {
            logger.error("Error during streaming recognition", e);
        }
public class BinaryAudioStreamReader extends PullAudioInputStreamCallback 
    {

         InputStream inputStream;

          public BinaryAudioStreamReader(byte[] data) 
          {
               inputStream = new ByteArrayInputStream(data);
          }

          @Override
          public int read(byte[] dataBuffer) 
          {
              try 
              {
                  return inputStream.read(dataBuffer, 0, dataBuffer.length);
              } 
              catch (IOException e) 
              {
                  e.printStackTrace();
              }
              return 0;
          }

          /**
           * Closes the audio input stream.
           */
          @Override
          public void close() 
          {
              try
               {
                  inputStream.close();
              } 
              catch (IOException e) 
              {
                  e.printStackTrace();
              }
          }
    }

Error : CANCELED: ErrorDetails=Runtime error: Failed to initialize platform (azure-c-shared). Error: 2176 SessionId: 5481c0a5bfe54f879307d5a782609421 CANCELED: Did you set the speech resource key and region values? CANCELED: Reason=Error CANCELED: ErrorCode=ConnectionFailure CANCELED: ErrorDetails=Runtime error: Failed to initialize platform (azure-c-shared). Error: 2176 SessionId: 6514400b059d4c85bf28c6fc454fddb5 CANCELED: Did you set the speech resource key and region values? CANCELED: Reason=Error CANCELED: ErrorCode=ConnectionFailure CANCELED: ErrorDetails=Runtime error: Failed to initialize platform (azure-c-shared). Error: 2176 SessionId: a87b07d1bc444cd7881c4a9b0d918c0b CANCELED: Did you set the speech resource key and region values?

BrianMouncer commented 3 months ago

the above code looks correct, and the exception you pasted generally means there is either something wrong with your key/region, or a base network connection error. I am not familiar with jigasi, but is there a chance you need to do something to have network access -- either a permission setting or configuring some kind of proxy?

I would verify your key and region are working with one of our samples on your local machine, then move on to looking into why the connection might fail in the jigasi service host?

Do you have the ability to collect sdk logs files from our SDK. and attach them here?

github-actions[bot] commented 2 months ago

This item has been open without activity for 19 days. Provide a comment on status and remove "update needed" label.

pankopon commented 1 month ago

Closed since no logs or other updates.