一:文字轉語音SDK安裝
安裝語音 SDK - Azure AI services | Microsoft Learn
二:基于文本轉語音Rest API
文本轉語音 API 參考 (REST) - 語音服務 - Azure AI services | Microsoft Learn
三:基于文本合成語音
如何基于文本合成語音 - 語音服務 - Azure AI services | Microsoft Learn
// YourSpeechKey : 私鑰;YourSpeechRegion:區域
public static void main(String[] args) {SpeechConfig speechConfig = SpeechConfig.fromSubscription("YourSpeechKey", "YourSpeechRegion");speechConfig.setSpeechSynthesisLanguage("en-US");speechConfig.setSpeechSynthesisVoiceName("en-US-AvaMultilingualNeural");// set the output formatspeechConfig.setSpeechSynthesisOutputFormat(SpeechSynthesisOutputFormat.Riff24Khz16BitMonoPcm);SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(speechConfig, null);SpeechSynthesisResult result = speechSynthesizer.SpeakText("I'm excited to try text to speech");AudioDataStream stream = AudioDataStream.fromResult(result);stream.saveToWavFile("D:\\file.wav");}