speak_lib.h

来自「a good tool for converting text to speec」· C头文件 代码 · 共 594 行 · 第 1/2 页

H
594
字号
#ifndef SPEAK_LIB_H#define SPEAK_LIB_H/*************************************************************************** *   Copyright (C) 2005 to 2007 by Jonathan Duddington                     * *   email: jonsd@users.sourceforge.net                                    * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 3 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, see:                                 * *               <http://www.gnu.org/licenses/>.                           * ***************************************************************************//*************************************************************//* This is the header file for the library version of espeak *//*                                                           *//*************************************************************/#define ESPEAK_API __declspec(dllexport)#include <stdio.h>#define ESPEAK_API_REVISION  3/*Revision 2   Added parameter "options" to eSpeakInitialize()Revision 3   Added espeakWORDGAP to  espeak_PARAMETER*/         /********************/         /*  Initialization  */         /********************/typedef enum {  espeakEVENT_LIST_TERMINATED = 0, // Retrieval mode: terminates the event list.  espeakEVENT_WORD = 1,            // Start of word  espeakEVENT_SENTENCE,            // Start of sentence  espeakEVENT_MARK,                // Mark  espeakEVENT_PLAY,                // Audio element  espeakEVENT_END,                 // End of sentence  espeakEVENT_MSG_TERMINATED,      // End of message  espeakEVENT_PHONEME              // Phoneme, if enabled in espeak_Initialize()} espeak_EVENT_TYPE;typedef struct {	espeak_EVENT_TYPE type;	unsigned int unique_identifier; // message identifier (or 0 for key or character)	int text_position;    // the number of characters from the start of the text	int length;           // word length, in characters (for espeakEVENT_WORD)	int audio_position;   // the time in mS within the generated speech output data	int sample;           // sample id (internal use)	void* user_data;      // pointer supplied by the calling program	union {		int number;        // used for WORD and SENTENCE events. For PHONEME events this is the phoneme mnemonic.		const char *name;  // used for MARK and PLAY events.  UTF8 string	} id;} espeak_EVENT;/*    When a message is supplied to espeak_synth, the request is buffered and espeak_synth returns. When the message is really processed, the callback function will be repetedly called.   In RETRIEVAL mode, the callback function supplies to the calling program the audio data and an event list terminated by 0 (LIST_TERMINATED).   In PLAYBACK mode, the callback function is called as soon as an event happens.   For example suppose that the following message is supplied to espeak_Synth:    "hello, hello."   * Once processed in RETRIEVAL mode, it could lead to 3 calls of the callback function :   ** Block 1:   <audio data> +    List of events: SENTENCE + WORD + LIST_TERMINATED    ** Block 2:   <audio data> +   List of events: WORD + END + LIST_TERMINATED   ** Block 3:   no audio data   List of events: MSG_TERMINATED + LIST_TERMINATED   * Once processed in PLAYBACK mode, it could lead to 5 calls of the callback function:   ** SENTENCE   ** WORD (call when the sounds are actually played)   ** WORD   ** END (call when the end of sentence is actually played.)   ** MSG_TERMINATED   The MSG_TERMINATED event is the last event. It can inform the calling program to clear the user data related to the message.   So if the synthesis must be stopped, the callback function is called for each pending message with the MSG_TERMINATED event.   A MARK event indicates a <mark> element in the text.   A PLAY event indicates an <audio> element in the text, for which the calling program should play the named sound file.*/typedef enum {	POS_CHARACTER = 1,	POS_WORD,	POS_SENTENCE} espeak_POSITION_TYPE;typedef enum {	/* PLAYBACK mode: plays the audio data, supplies events to the calling program*/	AUDIO_OUTPUT_PLAYBACK, 	/* RETRIEVAL mode: supplies audio data and events to the calling program */	AUDIO_OUTPUT_RETRIEVAL, 	/* SYNCHRONOUS mode: as RETRIEVAL but doesn't return until synthesis is completed */	AUDIO_OUTPUT_SYNCHRONOUS,	/* Synchronous playback */	AUDIO_OUTPUT_SYNCH_PLAYBACK} espeak_AUDIO_OUTPUT;typedef enum {	EE_OK=0,	EE_INTERNAL_ERROR=-1,	EE_BUFFER_FULL=1,	EE_NOT_FOUND=2} espeak_ERROR;#ifdef __cplusplusextern "C"#endifESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output, int buflength, const char *path, int options);/* Must be called before any synthesis functions are called.   output: the audio data can either be played by eSpeak or passed back by the SynthCallback function.   buflength:  The length in mS of sound buffers passed to the SynthCallback function.   path: The directory which contains the espeak-data directory, or NULL for the default location.   options: bit 0: 1=allow espeakEVENT_PHONEME events.   Returns: sample rate in Hz, or -1 (EE_INTERNAL_ERROR).*/typedef int (t_espeak_callback)(short*, int, espeak_EVENT*);#ifdef __cplusplusextern "C"#endifESPEAK_API void espeak_SetSynthCallback(t_espeak_callback* SynthCallback);/* Must be called before any synthesis functions are called.   This specifies a function in the calling program which is called when a buffer of   speech sound data has been produced.    The callback function is of the form:int SynthCallback(short *wav, int numsamples, espeak_EVENT *events);   wav:  is the speech sound data which has been produced.      NULL indicates that the synthesis has been completed.   numsamples: is the number of entries in wav.  This number may vary, may be less than      the value implied by the buflength parameter given in espeak_Initialize, and may      sometimes be zero (which does NOT indicate end of synthesis).   events: an array of espeak_EVENT items which indicate word and sentence events, and      also the occurance if <mark> and <audio> elements within the text.  The list of      events is terminated by an event of type = 0.   Callback returns: 0=continue synthesis,  1=abort synthesis.*/#ifdef __cplusplusextern "C"#endifESPEAK_API void espeak_SetUriCallback(int (*UriCallback)(int, const char*, const char*));/* This function may be called before synthesis functions are used, in order to deal with   <audio> tags.  It specifies a callback function which is called when an <audio> element is   encountered and allows the calling program to indicate whether the sound file which   is specified in the <audio> element is available and is to be played.   The callback function is of the form:int UriCallback(int type, const char *uri, const char *base);   type:  type of callback event.  Currently only 1= <audio> element   uri:   the "src" attribute from the <audio> element   base:  the "xml:base" attribute (if any) from the <speak> element   Return: 1=don't play the sound, but speak the text alternative.           0=place a PLAY event in the event list at the point where the <audio> element             occurs.  The calling program can then play the sound at that point.*/         /********************/         /*    Synthesis     */         /********************/#define espeakCHARS_AUTO   0#define espeakCHARS_UTF8   1#define espeakCHARS_8BIT   2#define espeakCHARS_WCHAR  3#define espeakSSML        0x10#define espeakPHONEMES    0x100#define espeakENDPAUSE    0x1000#define espeakKEEP_NAMEDATA 0x2000#ifdef __cplusplusextern "C"#endifESPEAK_API espeak_ERROR espeak_Synth(const void *text,	size_t size,	unsigned int position,	espeak_POSITION_TYPE position_type,	unsigned int end_position,	unsigned int flags,	unsigned int* unique_identifier,	void* user_data);/* Synthesize speech for the specified text.  The speech sound data is passed to the calling   program in buffers by means of the callback function specified by espeak_SetSynthCallback(). The command is asynchronous: it is internally buffered and returns as soon as possible. If espeak_Initialize was previously called with AUDIO_OUTPUT_PLAYBACK as argument, the sound data are played by eSpeak.   text: The text to be spoken, terminated by a zero character. It may be either 8-bit characters,      wide characters (wchar_t), or UTF8 encoding.  Which of these is determined by the "flags"      parameter.   size: Equal to (or greatrer than) the size of the text data, in bytes.  This is used in order      to allocate internal storage space for the text.  This value is not used for      AUDIO_OUTPUT_SYNCHRONOUS mode.   position:  The position in the text where speaking starts. Zero indicates speak from the      start of the text.   position_type:  Determines whether "position" is a number of characters, words, or sentences.      Values:    end_position:  If set, this gives a character position at which speaking will stop.  A value      of zero indicates no end position.   flags:  These may be OR'd together:      Type of character codes, one of:         espeakCHARS_UTF8     UTF8 encoding         espeakCHARS_8BIT     The 8 bit ISO-8859 character set for the particular language.         espeakCHARS_AUTO     8 bit or UTF8  (this is the default)         espeakCHARS_WCHAR    Wide characters (wchar_t)      espeakSSML   Elements within < > are treated as SSML elements, or if not recognised are ignored.      espeakPHONEMES  Text within [[ ]] is treated as phonemes codes (in espeak's Hirshenbaum encoding).      espeakENDPAUSE  If set then a sentence pause is added at the end of the text.  If not set then         this pause is suppressed.   unique_identifier: message identifier; helpful for identifying later      data supplied to the callback.   user_data: pointer which will be passed to the callback function.   Return: EE_OK: operation achieved            EE_BUFFER_FULL: the command can not be buffered;              you may try after a while to call the function again.	   EE_INTERNAL_ERROR.*/#ifdef __cplusplusextern "C"#endifESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text,	size_t size,	const char *index_mark,	unsigned int end_position,	unsigned int flags,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?