0% found this document useful (0 votes)
90 views4 pages

Java Speech Recognition Guide

Código en lenguaje java que convierte en texto lo que hablas ... para ser implementado en un programa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views4 pages

Java Speech Recognition Guide

Código en lenguaje java que convierte en texto lo que hablas ... para ser implementado en un programa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Speech To Text using Java API

Sunday, February 6, 2011

In this post, we are going to learn about speech to text conversion using java speech API.
We will be discussing the following topics :

Brief about Speech Recognition.


Setup Speech Recognition engine
Verifying the Speech Recognition engine installation
Sample code
Conclusion

Speech Recognition is the process of converting spoken input to digital output, such as text.
Speech recognition systems provide computers with the ability to listen to user speech and
determine what is said.

The Speech Recognition process can be divided into these four steps:

1. Speech is converted to digital signals.


2. Actual speech sounds are extracted from the sounds (based on energy of the
sounds).
3. The extracted sounds are put together into 'speech frames.'
4. The speech frames are compared with words from the grammar file to determine the
spoken word.

We are going to use a third party java speech recognizer engine TalkingJava SDK which is
a full implementation of Sun's Java Speech API providing Text-To-Speech and Speech-
Recognition engines.

TalkingJava SDK website has been shutdown. I have shared the old SDK You can
download from here. Click Here
Four easy step to set up TalkingJava SDK

1. Download TalkingJava SDK Installer file : Download


2. Click on [Link] and follow the instruction to install SDK.
3. Unpack [Link] file. Then unpack [Link] (available inside
TalkingJavaSDK-1xx directory).
4. Copy [Link] and [Link] files available inside packet directory to your
Java\jdk1.x.x.x\jre\lib\ext\ direcoty.
5. Include your packet directory path into your CLASSPATH environment variable.

You can also refer to the installation guide here -cloudgarden installation

We are going to verify whether the speech recognition engine has been installed
successfully or not using a simple java program.
[Link]
?
1 package [Link];
2 package [Link];
3
4 import [Link];
5 import [Link];
6 import [Link];
7 import [Link];
8
9 public class TestRecognizerConfig {
10 public static void main(String[] args) {
11 try
12 {
13 [Link]
14 ("[Link]");
15 RecognizerModeDesc desc =
16 new RecognizerModeDesc([Link],[Link]);
17 EngineList el = [Link](desc);
18 if([Link]() < 1){
19 [Link]("Recognition Engine is not available");
20 [Link](1);
21 }else{
22 [Link]("Recognition Engine is available");
23 [Link](1);
24 }
25 }catch(Exception exception)
26 {
27 [Link]();
28 }
29 }
30}
Run this class file and check the output. If output is Recognition Engine is available then
you have installed recognition engine successfully and you are good to go.

[Link]
?
1 package [Link];
2
3 import [Link];
4 import [Link].*;
5 import [Link];
6 import [Link];
7
8 public class SpeechToTextConverter extends ResultAdapter {
9 static Recognizer recognizer;
10 public void resultAccepted(ResultEvent resultEvent) {
11 Result result = (Result)([Link]());
12 ResultToken resultToken[] = [Link]();
13 for (int nIndex = 0; nIndex < [Link]; nIndex++){
14 [Link](resultToken[nIndex].getSpokenText() + " ");
15 }
16 try {
17 // Deallocate the recognizer
18 [Link](true);
19 [Link]();
20 }catch (Exception exception) {
21 [Link]();
22 }
23 [Link](0);
24 }
25
26 public static void main(String args[]) {
27 try {
28 [Link]
29 ("[Link]");
30 RecognizerModeDesc desc =
31 new RecognizerModeDesc([Link],[Link]);
32 // Create a recognizer that supports US English.
33 recognizer = [Link](desc);
34 // Start up the recognizer
35 [Link]();
36 // Load the grammar from a file, and enable it
37 FileReader fileReader =
38 new FileReader("D:\\my_grammar.grammar");
39 RuleGrammar grammar = [Link](fileReader);
40 [Link](true);
41 // Add the listener to get results
42 [Link](new SpeechToTextConverter());
43 // Commit the grammar
44 [Link]();
45 [Link]([Link]);
46 // Request focus and start listening
47 [Link]();
48 [Link]();
49 [Link](Recognizer.FOCUS_ON);
50 [Link](true);
51 [Link]([Link]);
52 } catch (Exception e) {
53 [Link]();
54 [Link](0);
55 }
56 }
57}
A Little Grammer
The JSpeech Grammar Format (JSGF) is a platform-independent, vendor-independent
textual representation of grammars for use in speech recognition. Grammars are used by
speech recognizers to determine what the recognizer should listen for, and so describe the
utterances a user may say. JSGF adopts the style and conventions of the JavaTM
Programming Language in addition to use of traditional grammar notations. To know more
about JSGF.

You might also like