dk.brondsted.mssapi
dk.brondsted.MSSapi is a Java package providing easy high-level access from Java to Microsft SAPI 4.0 complient
Text-To-Speech synthesizers. The constructor loads a native dynamic library
TTSCommand.dll, implemented in C++ and linked to the Microsoft Speech SDK
4.0 spchwrap.lib (with Visual C++). An equivalent native library for other
platforms than Windows 32 systems can, of course, not be provided.
The package is "inspired" by the standard extension package javax.speech.synthesis
providing access to JSAPI compliant speech synthesizers on all platforms
(also Linux, Unix ...) and solves the problem with speech synthesis products
that only supports the Microsoft SAPI interface (e.g. the Danish speech
synthesizer by SpeechWare).
Note that the native library TTSCommand.dll can also be accessed from
C/C++ programs compiled with any 32-bit compiler on Windows systems. At
the bottom at this page there is a simple "Hello
World" coding example.
Package dk.brondsted.mssapi download
v. 0.1 beta
public class JMSSapiTTS
public JMSSapiTTS()
Loads the native library TTSCommand(.dll) located in the library
path. Per default the voice "Carsten" (male voice of the Danish speech
synthesizer by SpeechWare). If not found, the voice "Sam" (US-English male
synthesizer shipped with Microsoft SAPI 4.0) is loaded.
public void addVoice(String voice)
Similar to addVoice(Voice v)of javax.speech.synthesis.SynthesizerModeDesc.
However, the argument is simply the name of the voice. The available voices
can be displayed with the method getVoices (see below).
public void cancelAll()
Similar to cancelAll()of javax.speech.synthesiz.
Cancel all objects in the synthesizer speech output queue and stop speaking
the current top-of-queue object.
public void deallocate()
Similar to the javax.speech.Engine method. If deallocated
and an application invokes one of the other synthesizer methods (e.g. speakPlainText),
resources
are automatically reallocated by the native library. Applications would
normally only use the deallocate method if they interface to a
demo-synthesizer that, e.g., only accepts input for a certain period of
time.
public void getVoices()
Similar to the javax.speech.synthesis.SynthesizerModeDesc
method. However rather than returning an actual Voice[]
array, the method simply prints the names of the voices installed on the
machine to stdout. Subsequently, one of the names can be chosen
and used as argument for the addVoice method
public boolean isBusy()
Is an improvised solution to the problem that events like "TextDataStarted",
"TextDataDone" sent to the ITTSBufNotifySink on the SAPI-side
cannot be passed on to a SpeakableListener on the Java-side (see
speakPlainText
below). The native library simply counts the number of TextDataStarted-events
and substracts the number of TextDataDone-events. If the result
is >0, the method isBusy returns true, otherwise false.
public void pause()
Similar to the pause method inherited from javax.speech.Engine
in javax.speech.synthesiz. Pause the audio stream for the synthesizer.
public void resume()
Similar to the pause method inherited from javax.speech.Engine
in
javax.speech.synthesiz.
Resume
the audio stream for the synthesizer.
public void setPitchRange(float hertz)
Similar to the method of javax.speech.synthesis.SynthesizerProperties.
When setting the pitch, the native library also displays the minimum and
maxium values defined for the chosen voice.
public void setSpeakingRate(float wordsperminute)
Similar to the method of javax.speech.synthesis.SynthesizerProperties.
When setting the speaking rate, the native library also displays the minimum
and maxium values defined for the chosen voice.
public void speakPlainText(String text)
Similar to speakPlainText(String text, SpeakableListener
listener) of javax.speech.synthesiz. Note that the method
includes no SpeakableListener in it's arguments. The application can
access the isBusy method (see above) in a Timer object to keep
track on the state of the synthesizer. Note further that no method for
accepting text in the Java Speech API Markup Language (JSML) has been implemented.
Java text strings with national characters (Danish 'æ', 'ø',
'å' etc.) are translated correctly into the representations requred
by the native WIN32 system.
Hello World-program in C/C++ that interfaces
to TTSCommand.dll. The example can be compiled with both Visual C++ and
Borlands free bcc32 command line compiler.
#include <windows.h>
#include <stdio.h>
typedef LPCSTR (CALLBACK* DLL_COMMAND)(LPCSTR);
int main()
{
HINSTANCE hInstance=LoadLibrary("TTSCommand.dll");
if (hInstance==NULL) fprintf(stderr,"Failed to load
dll");
DLL_COMMAND TTSCmd=(DLL_COMMAND)GetProcAddress(hInstance,"TTSCommand");
if (TTSCmd==NULL) fprintf(stderr,"Failed to get procaddress
in dll");
(*TTSCmd)(NULL);//initialises. Default voice Carsten
if installed, otherwise Sam
#ifdef DANISH
(*TTSCmd)("Her ser du en række kommandoer til
at styre syntesen");
#else
(*TTSCmd)("#SETVOICE Sam");
(*TTSCmd)("On the screen you see a set of commands
to control the synthesis");
#endif
(*TTSCmd)("#HELP");
char wbuffer[1024];
while(1)
{
printf("\nReady: ");
fgets(wbuffer,1024,stdin); // Not
Unicode version!
if (wbuffer[0]=='\n') break; //empty
line
wbuffer[strlen(wbuffer)-1]='\0';//strip
newline character
(*TTSCmd)((LPCSTR)wbuffer);
}
FreeLibrary(hInstance);
return 0;
}
|