whyclj
2021-01-05 64aba412c2b739d67795b14a3cae069d311697f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com;
 
import java.io.IOException;
import java.util.Vector;
 
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.SourceDataLine;
 
import main.main_window;
 
//²¥·ÅÉùÒôµÄÀà
public class PlaySound extends Thread {
    Vector<Vector<Object>> vvo = null;
    public boolean is_running = true;
    private boolean sound_en = true;
    //private boolean voice_en;
    private String filename;
    //private String al_text;
    
    public PlaySound(String wav_file) {
        filename = "/sound/" + wav_file;
        this.start();
    }
    
    public void run() 
    {
        /**********************************************************************/
        if(true == sound_en) {
            javax.sound.sampled.AudioInputStream audioInputStream = null;
            try {
                audioInputStream = javax.sound.sampled.AudioSystem.getAudioInputStream(main_window.class.getResource(filename));
            } catch (Exception e1) {
                e1.printStackTrace();
                return;
            }
            
            AudioFormat format = audioInputStream.getFormat();
            SourceDataLine auline = null;
            javax.sound.sampled.DataLine.Info info = new javax.sound.sampled.DataLine.Info(SourceDataLine.class, format);
            try {
                auline = (SourceDataLine) javax.sound.sampled.AudioSystem.getLine(info);
                auline.open(format);
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
            
            auline.start();
            int nBytesRead = 0;
            byte[] abData = new byte[512];
            try {
                while (nBytesRead != -1) {
                    nBytesRead = audioInputStream.read(abData, 0, abData.length);
                    if (nBytesRead >= 0)
                        auline.write(abData, 0, nBytesRead);
                }
            } catch (IOException e) {
                e.printStackTrace();
                return;
            } finally {
                auline.drain();
                auline.close();
            }
        }
        /**********************************************************************/
        //while(vvo.size() > 0) 
        {/*
            Vector<Object> vo = vvo.get(0);
            sound_en = (boolean) vo.get(0);
            voice_en = (boolean) vo.get(1);
            filename = "/sound/" + vo.get(2);
            al_text = (String) vo.get(3);
            
            if(true == sound_en) {
                javax.sound.sampled.AudioInputStream audioInputStream = null;
                try {
                    audioInputStream = javax.sound.sampled.AudioSystem.getAudioInputStream(main_window.class.getResource(filename));
                } catch (Exception e1) {
                    e1.printStackTrace();
                    return;
                }
                
                AudioFormat format = audioInputStream.getFormat();
                SourceDataLine auline = null;
                javax.sound.sampled.DataLine.Info info = new javax.sound.sampled.DataLine.Info(SourceDataLine.class, format);
                try {
                    auline = (SourceDataLine) javax.sound.sampled.AudioSystem.getLine(info);
                    auline.open(format);
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }
                
                auline.start();
                int nBytesRead = 0;
                byte[] abData = new byte[512];
                try {
                    while (nBytesRead != -1) {
                        nBytesRead = audioInputStream.read(abData, 0, abData.length);
                        if (nBytesRead >= 0)
                            auline.write(abData, 0, nBytesRead);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    return;
                } finally {
                    auline.drain();
                    auline.close();
                }
            }*/
            /**********************************************************************/
            /*
            if(true == voice_en) {
                ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
                Dispatch sapo = (Dispatch) sap.getObject();
                try {
                    // ÒôÁ¿ 0-100
                    sap.setProperty("Volume", new Variant(100));
                    // ÓïÒôÀʶÁËÙ¶È -10 µ½ +10
                    sap.setProperty("Rate", new Variant(-5));
                    Dispatch.call(sapo, "Speak", new Variant(al_text));
                    
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    sapo.safeRelease();
                    sap.safeRelease();
                }
            }*/
            /**********************************************************************/
            //vvo.removeElementAt(0);
            /**********************************************************************/
        }
        /***********************************************************************************************/
        is_running = false;
        /***********************************************************************************************/
    }
}