Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
Ever wondered how would it look or feel if our ABAP programs speaks something. Great, right? I actually tried this after reading this blog. I used FreeTTS Speech project on source forge to accomplish my task. Before proceeding, let me tell you the program flow of the whole application(though small). I will first execute a java class file from ABAP and pass to this the contents which are to be spoken. This java code will actually save these contents onto a local file. Then I code a batch file on windows which in turn will execute another java program which in turn will read the contents from this local file and speak it out. Now without any other deviations lets start out work. First of all download the FreeTTS Speech Synthesis Engine from here. I downloaded the zip file onto my C drive and unzipped it. Then I set the classpath variable as shown in figure below. The code of first java file which takes parameters and save that onto a local file looks like this: import java.io.*; public class write_string { public static void main(String args[]){ try { BufferedWriter out = new BufferedWriter(new FileWriter("c:\\outfilename.txt")); int i=0; while (i < args.length) { out.write(args[i]); out.write(" "); i++; } out.close(); } catch (IOException e) { } } } Note that the name of the output file is hard coded here. The second java file which reads this file and speak it up looks like this: /** * @author I039850 * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ import java.io.*; import com.sun.speech.freetts.Voice; import com.sun.speech.freetts.VoiceManager; public class TEST { public static void main(String[] args) { try { VoiceManager voiceManager = VoiceManager.getInstance(); Voice voice = voiceManager.getVoice("kevin16"); voice.allocate(); BufferedReader in = new BufferedReader(new FileReader("outfilename.txt")); String str; while ((str = in.readLine()) != null) { voice.speak(str); } voice.deallocate(); } catch (Exception ex){ System.out.println( ex ); } } } The contents of the Windows batch file is: java TEST You must be wondering why I am using a batch file to execute a java program inside it. I could have called it directly from ABAP. Well when I was calling this java program directly(from ABAP), it wasnt playing anything for some god damn reason. So I played it well and called a batch file from ABAP which it turn executed the java class file. 🙂 My ABAP program looks like this: *&---------------------------------------------------------------------* *& Report ZEXECUTE *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZEXECUTE. *message 'SF' number '10'. data para type string. parameter mytext type objectname obligatory. *data mytext type string. para = 'write_string'. CONCATENATE para mytext into para separated by space. CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE EXPORTING * DOCUMENT = 'JAVA' APPLICATION = 'JAVA' PARAMETER = para DEFAULT_DIRECTORY = 'C:\' * MAXIMIZED = MINIMIZED = 'X' SYNCHRONOUS = 'WAIT' OPERATION = 'OPEN' EXCEPTIONS CNTL_ERROR = 1 ERROR_NO_GUI = 2 BAD_PARAMETER = 3 FILE_NOT_FOUND = 4 PATH_NOT_FOUND = 5 FILE_EXTENSION_UNKNOWN = 6 ERROR_EXECUTE_FAILED = 7 SYNCHRONOUS_FAILED = 8 NOT_SUPPORTED_BY_GUI = 9 others = 10 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE EXPORTING * DOCUMENT = 'JAVA' APPLICATION = 'my' * PARAMETER = 'jinvoker' DEFAULT_DIRECTORY = 'C:\' * MAXIMIZED = MINIMIZED = 'X' SYNCHRONOUS = 'WAIT' OPERATION = 'OPEN' EXCEPTIONS CNTL_ERROR = 1 ERROR_NO_GUI = 2 BAD_PARAMETER = 3 FILE_NOT_FOUND = 4 PATH_NOT_FOUND = 5 FILE_EXTENSION_UNKNOWN = 6 ERROR_EXECUTE_FAILED = 7 SYNCHRONOUS_FAILED = 8 NOT_SUPPORTED_BY_GUI = 9 others = 10 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. Write 'Success'. I am using execute method of class CL_GUI_FRONTEND_SERVICES to execute executables on local machine or presentation server. Note that in the function module call, I have given default directory as C:\. Now when I executed this ABAP report, it prompted me for a value. I gave the value and pressed F8 and bingo, Kevin spoke up that "value". Actually I feel that this small application and the blog which was written by Ignacio can be good starting point for SAP accessibility. And am now trying to extend this application such that whenever an error is poppped up, Kevin would speak it up. Btw Thanks Amit and Saurabh for helping me on Java front.
17 Comments