天天看点

图灵机器人(Java语音版)

系列文章:

Java 语音记录(录音,存储为WAV文件):https://blog.csdn.net/haoranhaoshi/article/details/87888382

Java 语音识别(百度语音API):https://blog.csdn.net/haoranhaoshi/article/details/87888407

Java 语音合成并播放(百度语音API):https://blog.csdn.net/haoranhaoshi/article/details/87888430

Java 语音聊天机器人(百度语音API)(当前预置问答,可用图灵机器人框架扩展):

https://blog.csdn.net/haoranhaoshi/article/details/87888469 (依赖前三篇博客代码)

百度语音实战下载:https://download.csdn.net/download/haoranhaoshi/10976591

图灵机器人(Java文字版):https://blog.csdn.net/haoranhaoshi/article/details/87992548

图灵机器人(Java语音版):https://blog.csdn.net/haoranhaoshi/article/details/87992661 

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

/**
 * 按住按钮或者按住Ctrl说话
 * 包含丰富的语料库,即使同一个沟通语句,也有不同的回答
 */
public class TulingCommunicationByVoice extends Application {
    private VoiceCompose voiceCompose = new VoiceCompose();
    private VoiceRecognition voiceRecognition = new VoiceRecognition();
    private VoiceRecorder voiceRecorder = new VoiceRecorder();

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        Label label = new Label("按住按钮或者按住Ctrl说话");
        Button button = new Button("按住说话");
        FlowPane flowPane = new FlowPane(label, button);
        flowPane.setAlignment(Pos.CENTER);
        flowPane.setOrientation(Orientation.HORIZONTAL);
        flowPane.setPrefHeight(80);
        flowPane.setPrefWidth(200);
        flowPane.setVgap(20);

        button.setOnMousePressed(event -> voiceRecorder.captureAudio());

        button.setOnMouseReleased(event -> responseMaster());

        flowPane.setOnKeyPressed(event -> voiceRecorder.captureAudio());

        flowPane.setOnKeyReleased(event -> responseMaster());

        primaryStage.setScene(new Scene(flowPane));
        primaryStage.show();
    }

    private void responseMaster() {
        voiceRecorder.closeCaptureAudio();

        if (voiceRecognition.recognizeVoice()) {
            String resultText = voiceRecognition.getResultText();
            TulingCommunicationByText tulingCommunicationByText = new TulingCommunicationByText();
            String response = tulingCommunicationByText.getResponse(resultText);
            if(!voiceCompose.getMP3ByText(response)){
                System.out.println("转换失败");
            }else{
                voiceCompose.playMP3();
            }
        }else{
            System.out.println("识别错误");
        }
    }
}
           

依赖我的其他博客:

http 工具类:https://blog.csdn.net/haoranhaoshi/article/details/87952162

Java 语音记录(录音,存储为WAV文件):https://blog.csdn.net/haoranhaoshi/article/details/87888382

Java 语音识别(百度语音API):https://blog.csdn.net/haoranhaoshi/article/details/87888407

Java 语音合成并播放(百度语音API):https://blog.csdn.net/haoranhaoshi/article/details/87888430