Jacob Java voice broadcast

Explain first:
Jacob is the abbreviation of Java com bridge, which builds a bridge between Java and Microsoft COM components. Using the DLL DLL of Jacob and JNI to call com program on Java platform;
So as long as you have the right calling method, you can use java language to operate most functions of windows,
Language broadcast is one of them. It can adjust the speed of voice and the size of voice. For example, it can operate printer and office...
Various documents can also be converted into HTML or web page easy to display format. Of course, there are many other methods. Here I just want to say that jacob is very powerful,

What needs to be done:

1. Download jacob-1.17-M2.rar

2. Unzip jacob-1.17-M2.rar

3. Import jacob.jar into the project

4. Copy jacob-1.17-M2-x86.dll to the bin directory and windows/system32 directory of jdk

5. The source code is as follows:
package test;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class YuYin {

public static void main(String[] args) {
    // TODO Auto-generated method stub
     ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");  
        try {  
            // Volume 0-100  
            sap.setProperty("Volume", new Variant(100));  
            // Voice reading speed - 10 to + 10  
            sap.setProperty("Rate", new Variant(-2));  
            // Get execution object  
            Dispatch sapo = sap.getObject();  
            // Read aloud  
            Dispatch.call(sapo, "Speak", new Variant("Hello: as many as Asda."));  
            // Close execution object  
            sapo.safeRelease();  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            // Close application connection  
            sap.safeRelease();  
        }  

        strat("What are you doing? I really like you. I love you",0);

}

  public static void strat(String content, int type) {  
        // ??  Does this Sapi.SpVoice need to install anything? I feel like it's coming for no reason  
        ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");  
        // What does Dispatch do?  
        Dispatch sapo = sap.getObject();  

        if (type == 0) {  
            try {  
                // Volume 0-100  
                sap.setProperty("Volume", new Variant(100));  
                // Voice reading speed - 10 to + 10  
                sap.setProperty("Rate", new Variant(1.3));  
                Variant defalutVoice = sap.getProperty("Voice");  

                Dispatch dispdefaultVoice = defalutVoice.toDispatch();  
                Variant allVoices = Dispatch.call(sapo, "GetVoices");  
                Dispatch dispVoices = allVoices.toDispatch();  

                Dispatch setvoice = Dispatch.call(dispVoices, "Item",  
                        new Variant(1)).toDispatch();  
                ActiveXComponent voiceActivex = new ActiveXComponent(  
                        dispdefaultVoice);  
                ActiveXComponent setvoiceActivex = new ActiveXComponent(  
                        setvoice);  

                Variant item = Dispatch.call(setvoiceActivex, "GetDescription");  
                // Read aloud  
                Dispatch.call(sapo, "Speak", new Variant(content));  

            } catch (Exception e) {  
                e.printStackTrace();  
            } finally {  
                sapo.safeRelease();  
                sap.safeRelease();  
            }  
        } else {  
            // Stop it  

            try {  
                Dispatch.call(sapo, "Speak", new Variant(content), new Variant(  
                        2));  
            } catch (Exception e) {  
                System.out.println(e.getMessage());  
                e.printStackTrace();  
            }  
        }  

    }  

}

Tags: Java Windows JDK

Posted on Sun, 03 May 2020 06:33:31 -0400 by rawky1976