当前位置:   article > 正文

Azure的tts文本转语音服务使用_speechkey

speechkey

使用文件接收音频文件即可跳过播报过程:

  1. package com.tts;
  2. import com.microsoft.cognitiveservices.speech.*;
  3. import com.microsoft.cognitiveservices.speech.audio.AudioConfig;
  4. import java.io.*;
  5. import java.util.Arrays;
  6. import java.util.Scanner;
  7. import java.util.concurrent.ExecutionException;
  8. import java.util.concurrent.TimeUnit;
  9. /**
  10. * 文本转语音
  11. * @author dftdla
  12. */
  13. public class SpeechSynthesis {
  14. private static final String speechKey;
  15. private static final String speechRegion;
  16. //情绪度
  17. private static final String styleDegree = "1.4";
  18. //情绪
  19. private static final String style = "excited";
  20. //停顿点持续时间
  21. private static final String commasilenceExact = "600ms";
  22. //设置超时时间为5s
  23. private static final long timeout = 5;
  24. private static final TimeUnit unit = TimeUnit.SECONDS;
  25. public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
  26. //替换成自己的key和regin
  27. SpeechConfig speechConfig = SpeechConfig.fromSubscription(speechKey, speechRegion);
  28. //azure中菲律宾的女音 : fil-PH-BlessicaNeural
  29. speechConfig.setSpeechSynthesisVoiceName("en-IE-EmilyNeural");
  30. SpeechSynthesizer speechSynthesizer;
  31. String text;
  32. Scanner scanner = new Scanner(System.in);
  33. text = scanner.next();
  34. speechConfig.setSpeechSynthesisOutputFormat(SpeechSynthesisOutputFormat.Riff24Khz16BitMonoPcm);
  35. File file = new File("E:\\home\\admin\\source\\upload\\audio\\00a4da29-eec2-4464-8315-d9d7789f7240.wav");
  36. file.getParentFile().mkdirs();
  37. AudioConfig audioConfig = AudioConfig.fromWavFileOutput(file.getAbsolutePath());
  38. try {
  39. speechSynthesizer = new SpeechSynthesizer(speechConfig, audioConfig);
  40. SpeechSynthesisResult result = speechSynthesizer.SpeakText(text);
  41. speechSynthesizer.StartSpeakingText(Arrays.toString(result.getAudioData()));
  42. // speechSynthesizer.waitUntilDone();
  43. speechSynthesizer.StopSpeakingAsync();
  44. } catch(Exception ex) {
  45. System.out.println(ex.getMessage()+"??");
  46. } finally {
  47. System.out.println("done");
  48. }
  49. System.exit(0);
  50. }
  51. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/278361
推荐阅读
相关标签
  

闽ICP备14008679号