0

我是 Java 新手。我正在尝试构建一个 Java 桌面应用程序,它读取一个文本文件并为该文本创建一个音频文件。我被困在一个点上,即我编写了一个不会创建新音频的代码文件当它覆盖现有的音频文件时。但我无法制作这样的程序来创建新的音频文件,其中存储了给定文本文件的音频格式。请帮助我解决这个问题。

public class Main {
public static void main(String[] args) {

try {
    AudioPlayer audioPlayer = null;
    String voiceName = "kevin16";
     System.out.println();
    System.out.println("Using voice: " + voiceName);
    
  
    VoiceManager voiceManager = VoiceManager.getInstance();
    Voice helloVoice = voiceManager.getVoice(voiceName);
    
    if (helloVoice == null) {
        System.err.println("Cannot find a voice named "+ voiceName + ".  Please specify a different voice.");
        System.exit(1);
    }
    
  
    helloVoice.allocate();


    audioPlayer = new 
    SingleFileAudioPlayer("C:\\Users\\CZ\\Downloads\\output",Type.WAVE);

    helloVoice.setAudioPlayer(audioPlayer);

    Scanner sc = new Scanner(new File("C:\\Users\\CZ\\Documents\\\\java.txt"));
    while (sc.hasNextLine()) {
    helloVoice.speak(sc.nextLine());
    }







     helloVoice.deallocate();

      audioPlayer.close();
      System.exit(0);
      } catch (FileNotFoundException ex) {
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
     }
       }

     }
4

0 回答 0