Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About SpeakTextAsync, I only want the audioData, Don't want a sound, How to config ?

c-yyy opened this issue · comments

commented

Here is the JAVA code:

try {
      SpeechSynthesisResult result = synthesizer.SpeakTextAsync(text).get();
      if (result.getReason() == ResultReason.SynthesizingAudioCompleted) {
          synthesizer.StopSpeakingAsync();
          System.out.println("Speech synthesized for text [" + text + "]");
          audioData = result.getAudioData();
      } else if (result.getReason() == ResultReason.Canceled) {
          SpeechSynthesisCancellationDetails cancellation = SpeechSynthesisCancellationDetails.fromResult(result);
          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 update the subscription info?");
          }
      }

      result.close();
  } catch (Exception e) {
      e.printStackTrace();
  } finally {
      synthesizer.close();
}

You can take a look at the following code. It has samples that show how to save the audio to a wav file, an mp3 file or a push/pull
audio stream. You can use one of these instead of playing the audio through the speakers.
https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/java/jre/console/src/com/microsoft/cognitiveservices/speech/samples/console/SpeechSynthesisSamples.java

commented

You can take a look at the following code. It has samples that show how to save the audio to a wav file, an mp3 file or a push/pull audio stream. You can use one of these instead of playing the audio through the speakers. https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/java/jre/console/src/com/microsoft/cognitiveservices/speech/samples/console/SpeechSynthesisSamples.java

Oh, thank you~ I solved the problem.