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

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

Closed c-yyy closed 2 months ago

c-yyy commented 2 months ago

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();
}
jychoudh commented 2 months ago

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

c-yyy commented 2 months ago

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.