plugin/adin_oss.c File Reference

A reference sample of A/D-in plugin. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "plugin_defs.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/soundcard.h>

Go to the source code of this file.

Defines

#define PLUGIN_TITLE   "A/D-in plugin for Julius"
 Description string of this plugin file.
#define INPUT_OPT   "myadin"
 string to be specified at "-input" option at Julius to use this plugin as input module.

Functions

int initialize ()
 Initialization at loading time (optional).
int get_plugin_info (int opcode, char *buf, int buflen)
 Get information of this plugin (required).
void adin_get_optname (char *buf, int buflen)
 Return option string to select at option.
int adin_get_configuration (int opcode)
 Return decoder parameter values related to this adin plugin (required).
boolean adin_standby (int sfreq, void *dummy)
 Initialize input device (required).
boolean adin_open ()
 Open an input stream (required).
int adin_read (SP16 *buf, int sampnum)
 Read samples from device (required).
boolean adin_close ()
 Close the current input stream (required).
boolean adin_terminate ()
 A hook for Termination request (optional).
boolean adin_pause ()
 A hook for Pause request (optional).
boolean adin_resume ()
 A hook for Resume request (optional).

Variables

static int audio_fd
static int freq


Detailed Description

A reference sample of A/D-in plugin.

This file describes the specifications of plugin functions to be defined to make an A/D-in plugin. An A/D-in plugin will extend a new audio sream input into Julius by addin a new choice to the "-input" option.

The recording format should be 16 bit (signed short), and sampling rate should be set to the given value at adin_standby().

Common functions that can be defined in any type of plugin:

A/D-in plugin functions:

Required:

Optional:

Author:
Akinobu Lee
Date:
Thu Aug 7 14:28:37 2008
Revision
1.1

Definition in file adin_oss.c.


Function Documentation

int initialize (  ) 

Initialization at loading time (optional).

If defined, this will be called just before this plugin is loaded to Julius. if this returns -1, the whole functions in this file will not be loaded.

This function is OPTIONAL.

Returns:
0 on success, -1 on failure.

Definition at line 113 of file adin_oss.c.

int get_plugin_info ( int  opcode,
char *  buf,
int  buflen 
)

Get information of this plugin (required).

This function should return informations of this plugin file. The required info will be specified by opcode:

This will be called just after Julius find this file and after initialize().

Parameters:
opcode [in] requested operation code
buf [out] buffer to store the return string
buflen [in] maximum length of buf
Returns:
0 on success, -1 on failure. On failure, Julius will ignore this plugin.

Definition at line 155 of file adin_oss.c.

void adin_get_optname ( char *  buf,
int  buflen 
)

Return option string to select at option.

(required)

This function should return option string which should be specified as an argument "-input" option, to be used on Julius. The returning string should not be the same with any existing value.

This function will be called several times at option parsing at startup.

Parameters:
buf [out] buffer to store the return string
buflen [in] maximum length of buf

Definition at line 200 of file adin_oss.c.

int adin_get_configuration ( int  opcode  ) 

Return decoder parameter values related to this adin plugin (required).

This function should return configuration values about how to set up decoder to use this adin plugin. The return value is dependent on the given opcode, as described below:

opcode = 0: return whether real-time processing of 1st pass should be enabled by default.

if returns 0 (disabled) , Julius will do buffered input, spooling the incoming input till EOF or silence cut segmentation, extract feature vector, then recognize the whole. If returns 1 (enabled), on-the-fly decoding will be performed, reading input and decoding it concurrently.

A real-time decoding uses some approximation on feature extraction related to sentence-based normalization i.e. CMN or energy normalization. This value is typically 0 on off-line recognition, and 1 for on-line recognition.

This value is device-dependent default value, and can be overridden by user option "-realtime" and "-norealtime".

opcode = 1: return whether silence cut segmentation should be enabled by default

return 0 to disable, 1 to enable.

On file input, you can choose whether silence detection and segmentation should be performed before recognition. On live input like microphone, where input stream is infinite, you would perfer choose 1 to enable it.

This value is device-dependent default value, and can be overridden by user option "-cutsilence" and "-nocutsilence".

opcode = 2: return whether input threading is necessary or not.

On Unix, when set to 1, Julius forks a separate thread for A/D-in input. It can be useful when recognition is slow and some audio inputs are dropped. Note that this should be enabled only for infinite input like microphone or line input, since EOF handling on threaded mode is not supported yet. Recommended value is 1 for microphone input, 0 for file and network (tcp/ip) input. Ignored on Win32.

Parameters:
opcode [in] requested operation code
Returns:
values required for the opcode as described.

Definition at line 310 of file adin_oss.c.

boolean adin_standby ( int  sfreq,
void *  dummy 
)

Initialize input device (required).

This will be called only once at start up of Julius. You can initialize the device, check if the device exists or prepare a socket for connection.

If this function returns FALSE, Julius will exit.

JuliusLib: this function will be called at j_adin_init().

Parameters:
sfreq [in] required sampling frequency
dummy [in] a dummy data
Returns:
TRUE on success, FALSE on failure.

Definition at line 405 of file adin_oss.c.

boolean adin_open (  ) 

Open an input stream (required).

This function should open a new audio stream for input. You may open a capture device, open an audio file, or wait for connection with other network client at this function.

If this function returns FALSE, Julius will exit recognition loop.

JuliusLib: this will be called at j_open_stream().

Returns:
TRUE on success, FALSE on failure.

Definition at line 440 of file adin_oss.c.

int adin_read ( SP16 buf,
int  sampnum 
)

Read samples from device (required).

This function is for reading samples to be recognized from input stream. This will be called repeatedly at each time the read samples are fully processed.

The sampling format should be 16bit, 1 channel.

sampnum is the maximum number of samples that can be read into buf. The actual number of read samples should be returned.

Impotant notes about I/O blocking:

So the ideal operation will be first wait_for_some_data_to_come, and if any data becomes available, read them at most sampnum samples and return the number of read samples.

Positive return value should be the number of read samples, or one of ADIN_EOF, ADIN_SEGMENT or ADIN_ERROR. Return value of ADIN_EOF tells end of stream, which causes Julius to finish current recognition and close stream. ADIN_SEGMENT requests Julius to segment the current input. The current recognition will be stopped at this point, recognition result will be output, and then Julius continues to the next input. The behavior of ADIN_SEGMENT is similar to ADIN_EOF except that ADIN_SEGMENT does not close/open stream, but just stop and restart the recognition. At last, return value should be ADIN_ERROR on error, in which Julius exits itself immediately.

Parameters:
buf [out] output buffer to store samples obtained.
sampnum [in] maximum number of samples that can be stored in buf.
Returns:
actural number of read samples, ADIN_EOF on end of stream, ADIN_SEGMENT to request segmentation to Julius, or ADIN_ERROR on error.

Definition at line 583 of file adin_oss.c.

boolean adin_close (  ) 

Close the current input stream (required).

This function will be called when the input stream has reached end of file (i.e. the last call of adin_read() returns ADIN_EOF)

You may close a capture device, close an audio file, or disconnect network client.

If this function returns TRUE, Julius will go again to adin_open() to open another stream. If returns FALSE, Julius will exit the recognition loop.

JuliusLib: This will be called at the end of j_recognize_stream().

Returns:
TRUE on success, FALSE on failure.

Definition at line 643 of file adin_oss.c.

boolean adin_terminate (  ) 

A hook for Termination request (optional).

This function will be called when Julius receives a Termination request to stop running. This can be used to synchronize input facility with Julius's running status.

Termination will occur when Julius is running on module mode and received TERMINATE command from client, or j_request_terminate() is called inside application. On termination, Julius will stop recognition immediately (discard current input if in process), and wait until received RESUME command or call of j_request_resume().

This hook function will be called just after a Termination request. Please note that this will be called when Julius receives request, not on actual termination.

Returns:
TRUE on success, FALSE on failure.

Definition at line 696 of file adin_oss.c.

boolean adin_pause (  ) 

A hook for Pause request (optional).

This function will be called when Julius receives a Pause request to stop running. This can be used to synchronize input facility with Julius's running status.

Pause will occur when Julius is running on module mode and received PAUSE command from client, or j_request_pause() is called inside application. On pausing, Julius will stop recognition and then wait until it receives RESUME command or j_request_resume() is called. When pausing occurs while recognition is running, Julius will process it to the end before stops.

This hook function will be called just after a Pause request. Please note that this will be called when Julius receives request, not on actual pause.

Returns:
TRUE on success, FALSE on failure.

Definition at line 752 of file adin_oss.c.

boolean adin_resume (  ) 

A hook for Resume request (optional).

This function will be called when Julius received a resume request to recover from pause/termination status.

Resume will occur when Julius has been stopped by receiving RESUME command from client on module mode, or j_request_resume() is called inside application.

This hook function will be called just after a resume request. This can be used to make this A/D-in plugin cooperate with the pause/resume status, for example to tell audio client to restart audio streaming.

This function is totally optional.

Returns:
TRUE on success, FALSE on failure.

Definition at line 799 of file adin_oss.c.


Generated on Thu Jul 23 12:14:20 2009 for Julius by  doxygen 1.5.1