First you will need to run julius with the -module option (documentation here or man julius). Julius will wait for a client to connect, this is what Client does in a threaded way.
Let’s just write a simple program that will print whatever the julius server sends until you press CTRL+C:
#!/usr/bin/env python
import sys
import pyjulius
import Queue
# Initialize and try to connect
client = pyjulius.Client('localhost', 10500)
try:
client.connect()
except pyjulius.ConnectionError:
print 'Start julius as module first!'
sys.exit(1)
# Start listening to the server
client.start()
try:
while 1:
try:
result = client.results.get(False)
except Queue.Empty:
continue
print repr(result)
except KeyboardInterrupt:
print 'Exiting...'
client.stop() # send the stop signal
client.join() # wait for the thread to die
client.disconnect() # disconnect from julius
If you are only interested in recognitions, wait for an instance of Sentence objects in the queue:
if isinstance(result, pyjulius.Sentence):
print 'Sentence "%s" recognized with score %.2f' % (result, result.score)
If you do not want Client to interpret the raw xml Element, you can set modelize attribute to False
If you encounter any encoding issues, have a look at the -charconv option of julius and set the Client.encoding to the right value
More details about the use of the module can be found here
Connected client state
Disconnected client state
Threaded Client to connect to a julius module server
Parameters: |
|
---|
Host of the server
Port of the server
Encoding to use to decode socket’s output
Results received when listening to the server. This Queue is filled with raw xml Element objects and models (if modelize)
The socket used
Current state. State can be:
Connect to the server
Raises ConnectionError: | |
---|---|
If socket cannot establish a connection |
Disconnect from the server
Start listening to the server
Send a command to the server
Parameters: | command (string) – command to send |
---|
Stop the thread
Models are designed in order to represent the server response an object-oriented and easy way
A recognized sentence
Parameters: |
|
---|
Words that constitute the sentence
Score of the sentence
Constructor from xml element SHYPO
Parameters: |
|
---|
A word within a Sentence
Parameters: |
|
---|
Recognized word
Confidence of the recognized word
Constructor from xml element WHYPO
Parameters: |
|
---|
Base class for pyjulius exceptions
Raised when the initial connection to the server could not be established
Raised when could not send the command (timeout)