Java implementation of voice broadcast

1, Jar package download

  Link: https: //pan.baidu.com/s/1CrrLni304LOu_r9is8WRhA
  extraction code: wyi4

2, the introduction jar

  Jacob.jar copy directly to the lib folder of the project, and then Build Path;

  If maven project, the need to jacob.jar introducing local maven repository, then add dependent (method: https: //www.cnblogs.com/3b2414/p/11927455.html);

3, add dll

  I JDK is 32, so the added jacob-1.19-x86.dll in the bin directory under jre jdk directory (if 64-bit, is added jacob-1.19-x64.dll);

4,demo

public  static  void main (String [] args) {
     // Create a new connection with Microsoft applications. Incoming parameter is the name registered in the registry program. 
    SAP = ActiveXComponent new new ActiveXComponent ( "Sapi.SpVoice" );
     the try {
         // Volume 0-100 
        sap.setProperty ( "Volume", new new the Variant (100 ));
         // speech read-aloud speed from -10 to +10 
        sap.setProperty ( "Rate", new new the Variant (0 ));
         // Get the object performs 
        the Dispatch SAPO = sap.getObject ();
         // perform read 
        Dispatch.call (SAPO, "Speak", new newThe Variant ( "Data abnormal fluctuations" ));
         // Close the execution object 
        sapo.safeRelease (); 
    } the catch (Exception E) { 
        e.printStackTrace (); 
    } the finally {
         // close the application connection 
        sap.safeRelease (); 
    } 
} 

public  static  void jacobText (String path) throws Exception { 
    ActiveXComponent SAP = new new ActiveXComponent ( "Sapi.SpVoice" );
     // input file 
    file srcFile = new new file (path);
     // use of packaging character stream read files
    Br = the BufferedReader new new the BufferedReader ( new new the FileReader (srcFile)); 
    String Content = br.readLine ();
     the try {
         // Volume 0-100 
        sap.setProperty ( "Volume", new new the Variant (100 ));
         // speech read-aloud speed -10 to +10 
        sap.setProperty ( "Rate", new new the Variant (0 ));
         // Get the object performs 
        the Dispatch SAPO = sap.getObject ();
         // perform read 
        the while (Content =! null ) { 
            Dispatch.call ( SAPO, "Speak",new new the Variant (Content)); 
            Content = br.readLine (); 
        } 
        // close execution object 
        sapo.safeRelease (); 
    } the catch (Exception E) { 
        e.printStackTrace (); 
    } the finally { 
        br.close (); 
        / / close applications connect 
        sap.safeRelease (); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/3b2414/p/11927771.html