Differenze tra le versioni di ""Dal testo al parlato" mediante le funzioni esterne del API di Pico TTS"

Da Gambas-it.org - Wikipedia.
 
(6 versioni intermedie di uno stesso utente non sono mostrate)
Riga 3: Riga 3:
 
Le risorse della libreria di ''Pico TSS'' consentono di ottenere tale risultato, ed in particolare di leggere testo di sei fonemi diversi: inglese americano, inglese britannico, tedesco, spagnolo, francese ed italiano.
 
Le risorse della libreria di ''Pico TSS'' consentono di ottenere tale risultato, ed in particolare di leggere testo di sei fonemi diversi: inglese americano, inglese britannico, tedesco, spagnolo, francese ed italiano.
  
Per poter utilizzare tali risorse di ''Pico TSS'' bisognerà installare nel proprio sistema la libreria: ''libttspico.so.0.0.0'' .
+
Per poter utilizzare tali risorse di ''Pico TSS'' bisognerà installare nel proprio sistema la libreria condivisa: "''libttspico.so.0.0.0'' ".
  
  
 
Mostriamo di seguito un semplice esempio, nel quale si sottoporrà alla conversione di sintesi vocale un breve testo in italiano. In particolare il codice riprodurrà vocalmente il testo in un file WAV, nonché, utilizzando le fondamentali funzioni di ALSA, consentirà di ascoltare immediatamente quanto scritto nel testo.
 
Mostriamo di seguito un semplice esempio, nel quale si sottoporrà alla conversione di sintesi vocale un breve testo in italiano. In particolare il codice riprodurrà vocalmente il testo in un file WAV, nonché, utilizzando le fondamentali funzioni di ALSA, consentirà di ascoltare immediatamente quanto scritto nel testo.
'''Private''' Const MAX_OUTBUF_SIZE As Byte = 128
 
'''Private''' Const PICO_MEM_SIZE As Integer = 2500000
 
'''Private''' Const PICO_MAX_DATAPATH_NAME_SIZE As Byte = 128
 
'''Private''' Const PICO_MAX_FILE_NAME_SIZE As Byte = 64
 
'''Private''' Const PICO_LINGWARE_PATH As String = "/usr/share/pico/lang/"
 
'''Private''' Const PICO_MAX_RESOURCE_NAME_SIZE As Byte = 32
 
'''Private''' Const PICO_VOICE_NAME As String = "PicoVoice"
 
'''Private''' Const PICO_STEP_IDLE As Byte = 200                  <FONT color=gray>' ''No more input text available in the Pico text input buffer''</font>
 
'''Private''' Const PICO_STEP_BUSY As Byte = 201                  <FONT color=gray>' ''Process input and producing speech output''</font>
 
'''Private''' Const PICO_STEP_ERROR As Short = -200         
 
'''Private''' Const PICO_EXC_UNEXPECTED_FILE_TYPE As Short = -41
 
'''Private''' Const SAMPLE_FREQ_16KHZ As Integer = 16000
 
'''Private''' Const FORMAT_TAG_LIN As Byte = 1                    <FONT color=gray>' ''linear 16 - bit encoding''</font>
 
 
 
'''Private''' picoInternalTaLingware As String[] = ["en-US_ta.bin", "en-GB_ta.bin", "de-DE_ta.bin", "es-ES_ta.bin", "fr-FR_ta.bin", "it-IT_ta.bin"]
 
'''Private''' picoInternalSgLingware As String[] = ["en-US_lh0_sg.bin", "en-GB_kh0_sg.bin", "de-DE_gl0_sg.bin", "es-ES_zl0_sg.bin", "fr-FR_nk0_sg.bin", "it-IT_cm0_sg.bin"]
 
 
<FONT color=gray>'''''''''''''''''''''''''</font>
 
'''Private''' Const SND_PCM_STREAM_PLAYBACK As Byte = 0
 
'''Private''' Const SND_PCM_ACCESS_RW_INTERLEAVED As Byte = 3
 
'''Private''' Const nomen As String = "default"
 
<FONT color=gray>'''''''''''''''''''''''''</font>
 
 
 
 
  Library "libttspico:0.0.0"
 
  Library "libttspico:0.0.0"
 
   
 
   
 +
Private Const MAX_OUTBUF_SIZE As Byte = 128
 +
Private Const PICO_MEM_SIZE As Integer = 2500000
 +
Private Const PICO_MAX_DATAPATH_NAME_SIZE As Byte = 128
 +
Private Const PICO_MAX_FILE_NAME_SIZE As Byte = 64
 +
Private Const PICO_LINGWARE_PATH As String = "/usr/share/pico/lang/"
 +
Private Const PICO_MAX_RESOURCE_NAME_SIZE As Byte = 32
 +
Private Const PICO_VOICE_NAME As String = "PicoVoice"
 +
Private Const PICO_STEP_IDLE As Byte = 200                  <FONT color=gray>' ''No more input text available in the Pico text input buffer''</font>
 +
Private Const PICO_STEP_BUSY As Byte = 201                  <FONT color=gray>' ''Process input and producing speech output''</font>
 +
Private Const PICO_STEP_ERROR As Short = -200         
 +
Private Const PICO_EXC_UNEXPECTED_FILE_TYPE As Short = -41
 +
Private Const SAMPLE_FREQ_16KHZ As Integer = 16000
 +
Private Const FORMAT_TAG_LIN As Byte = 1                    <FONT color=gray>' ''linear 16 - bit encoding''</font>
 +
Private Const SND_PCM_STREAM_PLAYBACK As Byte = 0
 +
Private Const SND_PCM_FORMAT_S16_LE As Byte = 2
 +
Private Const SND_PCM_ACCESS_RW_INTERLEAVED As Byte = 3
 +
Private Const nomen As String = "default"
 +
Private picoInternalTaLingware As String[] = ["en-US_ta.bin", "en-GB_ta.bin", "de-DE_ta.bin", "es-ES_ta.bin", "fr-FR_ta.bin", "it-IT_ta.bin"]
 +
Private picoInternalSgLingware As String[] = ["en-US_lh0_sg.bin", "en-GB_kh0_sg.bin", "de-DE_gl0_sg.bin", "es-ES_zl0_sg.bin", "fr-FR_nk0_sg.bin", "it-IT_cm0_sg.bin"]
 +
 
 
  <FONT color=gray>' ''int pico_initialize(void *memory, const pico_Uint32 size, pico_System *outSystem)''
 
  <FONT color=gray>' ''int pico_initialize(void *memory, const pico_Uint32 size, pico_System *outSystem)''
 
  ' ''Initializes the Pico system and returns its handle in 'outSystem'.''</font>
 
  ' ''Initializes the Pico system and returns its handle in 'outSystem'.''</font>
  '''Private''' Extern pico_initialize(memP As Pointer, size As Integer, outSystem As Pointer) As Integer
+
  Private Extern pico_initialize(memP As Pointer, size As Integer, outSystem As Pointer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int pico_loadResource(pico_System system, const pico_Char *resourceFileName, pico_Resource *outResource)''
 
  <FONT color=gray>' ''int pico_loadResource(pico_System system, const pico_Char *resourceFileName, pico_Resource *outResource)''
 
  ' ''Loads a resource file into the Pico system.''</font>
 
  ' ''Loads a resource file into the Pico system.''</font>
  '''Private''' Extern pico_loadResource(pico_System As Pointer, resFileName$ As String, pico_Resource As Pointer) As Integer
+
  Private Extern pico_loadResource(pico_System As Pointer, resFileName$ As String, pico_Resource As Pointer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int pico_getResourceName(pico_System system, pico_Resource resource, pico_Retstring outName)''
 
  <FONT color=gray>' ''int pico_getResourceName(pico_System system, pico_Resource resource, pico_Retstring outName)''
 
  ' ''Gets the unique resource name of a loaded resource.''</font>
 
  ' ''Gets the unique resource name of a loaded resource.''</font>
  '''Private''' Extern pico_getResourceName(pico_System As Pointer, pico_Resource As Pointer, outName As Pointer) As Integer
+
  Private Extern pico_getResourceName(pico_System As Pointer, pico_Resource As Pointer, outName As Pointer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int pico_createVoiceDefinition(pico_System system, const pico_Char *voiceName)''
 
  <FONT color=gray>' ''int pico_createVoiceDefinition(pico_System system, const pico_Char *voiceName)''
 
  ' ''Creates a voice definition.''</font>
 
  ' ''Creates a voice definition.''</font>
  '''Private''' Extern pico_createVoiceDefinition(pico_System As Pointer, voiceName As String) As Integer
+
  Private Extern pico_createVoiceDefinition(pico_System As Pointer, voiceName As String) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int pico_addResourceToVoiceDefinition(pico_System system, const pico_Char *voiceName, const pico_Char *resourceName)''
 
  <FONT color=gray>' ''int pico_addResourceToVoiceDefinition(pico_System system, const pico_Char *voiceName, const pico_Char *resourceName)''
 
  ' ''Adds a mapping pair ('voiceName', 'resourceName') to the voice definition.''</font>
 
  ' ''Adds a mapping pair ('voiceName', 'resourceName') to the voice definition.''</font>
  '''Private''' Extern pico_addResourceToVoiceDefinition(pico_System As Pointer, voiceName As String, resourceName As Pointer) As Integer
+
  Private Extern pico_addResourceToVoiceDefinition(pico_System As Pointer, voiceName As String, resourceName As Pointer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int pico_newEngine(pico_System system, const pico_Char *voiceName, pico_Engine *outEngine)''
 
  <FONT color=gray>' ''int pico_newEngine(pico_System system, const pico_Char *voiceName, pico_Engine *outEngine)''
 
  ' ''Creates and initializes a new Pico engine instance and returns its handle in 'outEngine'.''</font>
 
  ' ''Creates and initializes a new Pico engine instance and returns its handle in 'outEngine'.''</font>
  '''Private''' Extern pico_newEngine(pico_System As Pointer, voiceName As String, outEngine As Pointer) As Integer
+
  Private Extern pico_newEngine(pico_System As Pointer, voiceName As String, outEngine As Pointer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''picoos_Common pico_sysGetCommon(pico_System this)''</font>
 
  <FONT color=gray>' ''picoos_Common pico_sysGetCommon(pico_System this)''</font>
  '''Private''' Extern pico_sysGetCommon(pico_System As Pointer) As Pointer
+
  Private Extern pico_sysGetCommon(pico_System As Pointer) As Pointer
 
   
 
   
 
  <FONT color=gray>' ''picoos_bool picoos_sdfOpenOut (picoos_Common g, picoos_SDFile * sdFile, picoos_char fileName[], int sf, picoos_encoding_t enc)''</font>
 
  <FONT color=gray>' ''picoos_bool picoos_sdfOpenOut (picoos_Common g, picoos_SDFile * sdFile, picoos_char fileName[], int sf, picoos_encoding_t enc)''</font>
  '''Private''' Extern picoos_sdfOpenOut(commP As Pointer, sdFile As Pointer, fileName As Pointer, sf As Integer, enc As Byte) as Boolean
+
  Private Extern picoos_sdfOpenOut(commP As Pointer, sdFile As Pointer, fileName As Pointer, sf As Integer, enc As Byte) as Boolean
 
   
 
   
 
  <FONT color=gray>' ''picoos_bool picoos_sdfCloseOut (picoos_Common g, picoos_SDFile * sdFile)''</font>
 
  <FONT color=gray>' ''picoos_bool picoos_sdfCloseOut (picoos_Common g, picoos_SDFile * sdFile)''</font>
  '''Private''' Extern picoos_sdfCloseOut(commP As Pointer, sdFile As Pointer) as Boolean
+
  Private Extern picoos_sdfCloseOut(commP As Pointer, sdFile As Pointer) as Boolean
 
   
 
   
 
  <FONT color=gray>' ''int pico_putTextUtf8(pico_Engine engine, const pico_Char *text, const pico_Int16 textSize, pico_Int16 *outBytesPut)''
 
  <FONT color=gray>' ''int pico_putTextUtf8(pico_Engine engine, const pico_Char *text, const pico_Int16 textSize, pico_Int16 *outBytesPut)''
 
  ' ''Puts text 'text' encoded in UTF8 into the Pico text input buffer''</font>
 
  ' ''Puts text 'text' encoded in UTF8 into the Pico text input buffer''</font>
  '''Private''' Extern pico_putTextUtf8(outEngine As Pointer, texP As Pointer, textsize As Short, outBytesPut As Pointer) As Integer
+
  Private Extern pico_putTextUtf8(outEngine As Pointer, texP As Pointer, textsize As Short, outBytesPut As Pointer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int pico_getData(pico_Engine engine, void *outBuffer, const pico_Int16 bufferSize, pico_Int16 *outBytesReceived, pico_Int16 *outDataType)''
 
  <FONT color=gray>' ''int pico_getData(pico_Engine engine, void *outBuffer, const pico_Int16 bufferSize, pico_Int16 *outBytesReceived, pico_Int16 *outDataType)''
 
  ' ''Gets speech data from the engine''</font>
 
  ' ''Gets speech data from the engine''</font>
  '''Private''' Extern pico_getData(engine As Pointer, outBuffer As Pointer, bufferSize As Short, outBytesReceived As Pointer, outDataType As Pointer) As Integer
+
  Private Extern pico_getData(engine As Pointer, outBuffer As Pointer, bufferSize As Short, outBytesReceived As Pointer, outDataType As Pointer) As Integer
+
 
<FONT color=gray>' ''picoos_bool picoos_sdfPutSamples (picoos_SDFile sdFile, picoos_uint32 nrSamples, picoos_int16 samples[])''</font>
 
'''Private''' Extern picoos_sdfPutSamples(sdFile As Pointer, buf As Byte, buff As Pointer) As Boolean
 
 
 
  <FONT color=gray>' ''pico_disposeEngine(pico_System system, pico_Engine *inoutEngine)''
 
  <FONT color=gray>' ''pico_disposeEngine(pico_System system, pico_Engine *inoutEngine)''
 
  ' ''Disposes a Pico engine and releases all memory it occupied.''</font>
 
  ' ''Disposes a Pico engine and releases all memory it occupied.''</font>
  '''Private''' Extern pico_disposeEngine(pico_System As Pointer, inoutEngine As Pointer)
+
  Private Extern pico_disposeEngine(pico_System As Pointer, inoutEngine As Pointer)
 
   
 
   
 
  <FONT color=gray>' ''pico_releaseVoiceDefinition(pico_System system, const pico_Char *voiceName)''
 
  <FONT color=gray>' ''pico_releaseVoiceDefinition(pico_System system, const pico_Char *voiceName)''
 
  ' ''Releases the voice definition 'voiceName'.''</font>
 
  ' ''Releases the voice definition 'voiceName'.''</font>
  '''Private''' Extern pico_releaseVoiceDefinition(pico_System As Pointer, voiceName As String)
+
  Private Extern pico_releaseVoiceDefinition(pico_System As Pointer, voiceName As String)
 
   
 
   
 
  <FONT color=gray>' ''pico_unloadResource(pico_System system, pico_Resource *inoutResource)''
 
  <FONT color=gray>' ''pico_unloadResource(pico_System system, pico_Resource *inoutResource)''
 
  ' ''Unloads a resource file from the Pico system.''</font>
 
  ' ''Unloads a resource file from the Pico system.''</font>
  '''Private''' Extern pico_unloadResource(pico_System As Pointer, inoutResource As Pointer)
+
  Private Extern pico_unloadResource(pico_System As Pointer, inoutResource As Pointer)
 
   
 
   
 
  <FONT color=gray>' ''pico_terminate(pico_System *system)''
 
  <FONT color=gray>' ''pico_terminate(pico_System *system)''
 
  ' ''Terminates the Pico system.''</font>
 
  ' ''Terminates the Pico system.''</font>
  '''Private''' Extern pico_terminate(pico_System As Pointer)
+
  Private Extern pico_terminate(pico_System As Pointer)
 
<FONT color=gray>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</font>
 
 
   
 
   
 
   
 
   
 
  Library "libasound:2"
 
  Library "libasound:2"
 
   
 
   
  <FONT color=gray>' ''int   snd_pcm_open(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode)''
+
  <FONT color=gray>' ''int snd_pcm_open(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode)''
  ' ''Apre il sub-sistema PCM''</font>
+
  ' ''Opens a PCM.''</font>
  '''Private''' Extern snd_pcm_open(pcmP As Pointer, nome As String, stream As Integer, mode As Integer) As Integer
+
  Private Extern snd_pcm_open(pcmP As Pointer, nome As String, stream As Integer, mode As Integer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''const char * snd_strerror (int errnum)''
 
  <FONT color=gray>' ''const char * snd_strerror (int errnum)''
 
  ' ''Returns the message For an Error code.''</font>
 
  ' ''Returns the message For an Error code.''</font>
  '''Private''' Extern snd_strerror(errnum As Integer) As String
+
  Private Extern snd_strerror(errnum As Integer) As String
 
   
 
   
 
  <FONT color=gray>' ''int snd_pcm_set_params (snd_pcm_t *pcm, snd_pcm_format_t format, snd_pcm_access_t access, unsigned int canali, unsigned int rate, int soft_resample, unsigned int latency)''
 
  <FONT color=gray>' ''int snd_pcm_set_params (snd_pcm_t *pcm, snd_pcm_format_t format, snd_pcm_access_t access, unsigned int canali, unsigned int rate, int soft_resample, unsigned int latency)''
 
  ' ''Set the hardware And software parameters''</font>
 
  ' ''Set the hardware And software parameters''</font>
  '''Private''' Extern snd_pcm_set_params(pcmP As Pointer, formatB As Byte, accessB As Byte, canali As Integer, rate As Integer, soft_resample As Integer, latency As Integer) As Integer
+
  Private Extern snd_pcm_set_params(pcmP As Pointer, formatB As Byte, accessB As Byte, canali As Integer, rate As Integer, soft_resample As Integer, latency As Integer) As Integer
+
 
<FONT color=gray>' ''int snd_pcm_start(snd_pcm_t *pcm)''</font>
 
'''Private''' Extern snd_pcm_start(pcmP As Pointer) As Integer
 
 
 
  <FONT color=gray>' ''snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)''
 
  <FONT color=gray>' ''snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)''
  ' ''Il terzo parametro "uframes" deve essere sempre uguale ad 1/4 del secondo parametro "buffer" !''</font>
+
  ' ''Write interleaved frames to a PCM.''</font>
  '''Private''' Extern snd_pcm_writei(pcmP As Pointer, buffP As Pointer, uframes As Long) As Integer
+
  Private Extern snd_pcm_writei(pcmP As Pointer, buffP As Pointer, uframes As Long) As Integer
 
   
 
   
  <FONT color=gray>' ''int snd_pcm_close(snd_pcm_t **pcm)''</font>
+
  <FONT color=gray>' ''int snd_pcm_close(snd_pcm_t **pcm)''
  '''Private''' Extern snd_pcm_close(pcmP As Pointer)
+
' ''Close PCM handle.''</font>
 +
  Private Extern snd_pcm_close(pcmP As Pointer)
 +
 
 
   
 
   
  <FONT color=gray>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</font>
+
  '''Public''' Sub Main()
 
   
 
   
+
   Dim picoMemArea, picoSystem As Pointer
Library "libc:6"
 
 
<FONT color=gray>' ''void *memcpy(void *str1, const void *str2, size_t n)''
 
' ''copies n characters from memory area str2 to memory area str1.''</font>
 
'''Private''' Extern memcpy(str1 As Pointer, str2 As Pointer, n As Integer)
 
 
 
'''Public''' Sub Form_Open()
 
 
   Dim buffer, local_text, picoMemArea, picoSystem As Pointer
 
 
   Dim picoTaResource, picoSgResource, picoTaResourceName As Pointer
 
   Dim picoTaResource, picoSgResource, picoTaResourceName As Pointer
 
   Dim picoSgResourceName, picoEngine, common, outBytesPut As Pointer
 
   Dim picoSgResourceName, picoEngine, common, outBytesPut As Pointer
   Dim testo, wav, sdOutFile, outbuf As Pointer
+
   Dim testo, wav, sdOutFile, outbuf, handle As Pointer
 +
  Dim buffer As Byte[]
 
   Dim resourceFileName, picoSgFileName As String
 
   Dim resourceFileName, picoSgFileName As String
 
   Dim buffersize As Short = 256
 
   Dim buffersize As Short = 256
   Dim ret, getstatus As Integer
+
   Dim ret, getstatus, err, obr, frames, letti As Integer
   Dim bytes_sent, bytes_recv, text_remaining, out_data_type, bufused As Short
+
  Dim st As Stream
+
   Dim bytes_sent, bytes_recv, text_remaining, out_data_type As Short
  Dim handle As Pointer
 
  Dim err, frames As Integer
 
  Dim risolBit As Integer = 2
 
 
   Dim frequenza As Integer = 8000
 
   Dim frequenza As Integer = 8000
 
   Dim canali As Byte = 2
 
   Dim canali As Byte = 2
 
 
   
 
   
 
  <FONT color=gray>' ''Apre il sub-sistema PCM di ALSA e gli passa dei valori per i parametri della riproduzione audio:''</font>
 
  <FONT color=gray>' ''Apre il sub-sistema PCM di ALSA e gli passa dei valori per i parametri della riproduzione audio:''</font>
    err = snd_pcm_open(VarPtr(handle), nomen, SND_PCM_STREAM_PLAYBACK, 0)
+
  err = snd_pcm_open(VarPtr(handle), nomen, SND_PCM_STREAM_PLAYBACK, 0)
      If err < 0 Then Error.Raise("Errore nell'apertura dell'interfaccia PCM di Alsa: " & snd_strerror(err))
+
  If err < 0 Then Error.Raise("Errore nell'apertura dell'interfaccia PCM di Alsa: " & snd_strerror(err))
 
   
 
   
    err = snd_pcm_set_params(handle, risolBit, SND_PCM_ACCESS_RW_INTERLEAVED, canali, frequenza, 1, 500000)
+
  err = snd_pcm_set_params(handle, SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, canali, frequenza, 1, 500000)
      If err < 0 Then Error.Raise("Errore nell'impostazione dei parametri dell'interfaccia PCM di Alsa: " & snd_strerror(err))
+
  If err < 0 Then Error.Raise("Errore nell'impostazione dei parametri dell'interfaccia PCM di Alsa: " & snd_strerror(err))
+
   
    err = snd_pcm_start(handle)
+
  <FONT color=gray>' ''Impostiamo il testo, al quale applicare la sintesi vocale:''</font>
      If err < 0 Then Error.Raise("Impossibile avviare il sub-sistema PCM di Alsa: " & snd_strerror(err))
+
  testo = Alloc("www.gambas-it.org è il sito della comunità italiana dei programmatori Gambas.")
 
 
  <FONT color=gray>' ''Impostiamo il testo, al quale applicare la sistesi vocale:''</font>
 
    testo = Alloc("www.gambas-it.org è il sito della comunità italiana dei programmatori Gambas.")
 
 
    
 
    
    buffer = Alloc(bufferSize)
+
  outbuf = Alloc(CInt(MAX_OUTBUF_SIZE / 2))
 
      
 
      
    outbuf = Alloc(CInt(MAX_OUTBUF_SIZE / 2))
+
  picoMemArea = Alloc(PICO_MEM_SIZE)
   
 
    picoMemArea = Alloc(PICO_MEM_SIZE)
 
 
      
 
      
 
  <FONT color=gray>' ''Inizializza la libreria 'libttspico':''</font>
 
  <FONT color=gray>' ''Inizializza la libreria 'libttspico':''</font>
    ret = pico_initialize(picoMemArea, PICO_MEM_SIZE, VarPtr(picoSystem))
+
  ret = pico_initialize(picoMemArea, PICO_MEM_SIZE, VarPtr(picoSystem))
    If ret < 0 Then Error.Raise("Impossibile inizializzare la libreria 'libttspico' !")
+
  If ret < 0 Then Error.Raise("Impossibile inizializzare la libreria 'libttspico' !")
 
   
 
   
 
  <FONT color=gray>' ''Carica il file lingware di risorse di analisi del testo.''
 
  <FONT color=gray>' ''Carica il file lingware di risorse di analisi del testo.''
 
  ' ''Per modificare la lingua di sintesi, cambiare il valore dell'indice della variabile "picoInternalTaLingware[]":''</font>
 
  ' ''Per modificare la lingua di sintesi, cambiare il valore dell'indice della variabile "picoInternalTaLingware[]":''</font>
    resourceFileName = PICO_LINGWARE_PATH & picoInternalTaLingware[5]
+
  resourceFileName = PICO_LINGWARE_PATH & picoInternalTaLingware[5]
 
   
 
   
    ret = pico_loadResource(picoSystem, resourceFileName, VarPtr(picoTaResource))  
+
  ret = pico_loadResource(picoSystem, resourceFileName, VarPtr(picoTaResource))  
    If ret < 0 Then Error.Raise("Errore alla funzione 'pico_loadResource' !")
+
  If ret < 0 Then Error.Raise("Errore alla funzione 'pico_loadResource' !")
 
+
   
 
 
 
  <FONT color=gray>' ''Carica il file lingware di risorse di generazione del segnale.''
 
  <FONT color=gray>' ''Carica il file lingware di risorse di generazione del segnale.''
 
  ' ''Per modificare la lingua di sintesi, cambiare il valore dell'indice della variabile "picoInternalSgLingware[]":''</font>
 
  ' ''Per modificare la lingua di sintesi, cambiare il valore dell'indice della variabile "picoInternalSgLingware[]":''</font>
  picoSgFileName = PICO_LINGWARE_PATH & picoInternalSgLingware[5]
+
  picoSgFileName = PICO_LINGWARE_PATH & picoInternalSgLingware[5]
   
 
    ret = pico_loadResource(picoSystem, picoSgFileName, VarPtr(picoSgResource))
 
 
 
      
 
      
 +
  ret = pico_loadResource(picoSystem, picoSgFileName, VarPtr(picoSgResource))
 +
     
 
  <FONT color=gray>' ''Ottiene il nome della risorsa di analisi del testo:''</font>
 
  <FONT color=gray>' ''Ottiene il nome della risorsa di analisi del testo:''</font>
    picoTaResourceName = Alloc(PICO_MAX_RESOURCE_NAME_SIZE)
+
  picoTaResourceName = Alloc(SizeOf(gb.Byte), PICO_MAX_RESOURCE_NAME_SIZE)
 
      
 
      
    ret = pico_getResourceName(picoSystem, picoTaResource, picoTaResourceName)
+
  ret = pico_getResourceName(picoSystem, picoTaResource, picoTaResourceName)
+
 
 
 
  <FONT color=gray>' ''Ottiene il nome della risorsa di generazione del segnale:''</font>
 
  <FONT color=gray>' ''Ottiene il nome della risorsa di generazione del segnale:''</font>
    picoSgResourceName = Alloc(PICO_MAX_RESOURCE_NAME_SIZE)
+
  picoSgResourceName = Alloc(SizeOf(gb.Byte), PICO_MAX_RESOURCE_NAME_SIZE)
   
 
    ret = pico_getResourceName(picoSystem, picoSgResource, picoSgResourceName)
 
 
 
      
 
      
 +
  ret = pico_getResourceName(picoSystem, picoSgResource, picoSgResourceName)
 +
 
 
  <FONT color=gray>' ''Crea una definizione vocale:''</font>
 
  <FONT color=gray>' ''Crea una definizione vocale:''</font>
    ret = pico_createVoiceDefinition(picoSystem, PICO_VOICE_NAME)
+
  ret = pico_createVoiceDefinition(picoSystem, PICO_VOICE_NAME)
 
   
 
   
   
 
 
  <FONT color=gray>' ''Aggiunge alla voce la risorsa di analisi del testo:''</font>
 
  <FONT color=gray>' ''Aggiunge alla voce la risorsa di analisi del testo:''</font>
    ret = pico_addResourceToVoiceDefinition(picoSystem, PICO_VOICE_NAME, picoTaResourceName)
+
  ret = pico_addResourceToVoiceDefinition(picoSystem, PICO_VOICE_NAME, picoTaResourceName)
 
   
 
   
   
 
 
  <FONT color=gray>' ''Aggiunge alla voce la risorsa di generazione del segnale:''</font>
 
  <FONT color=gray>' ''Aggiunge alla voce la risorsa di generazione del segnale:''</font>
    ret = pico_addResourceToVoiceDefinition(picoSystem, PICO_VOICE_NAME, picoSgResourceName)
+
  ret = pico_addResourceToVoiceDefinition(picoSystem, PICO_VOICE_NAME, picoSgResourceName)
 
   
 
   
   
 
 
  <FONT color=gray>' ''Crea a nuovo motore di sintetizzazione Pico:''</font>
 
  <FONT color=gray>' ''Crea a nuovo motore di sintetizzazione Pico:''</font>
    ret = pico_newEngine(picoSystem, PICO_VOICE_NAME, VarPtr(picoEngine))
+
  ret = pico_newEngine(picoSystem, PICO_VOICE_NAME, VarPtr(picoEngine))
 
 
   
 
   
 
  <FONT color=gray>' ''Imposta il percorso ed il nome del file wav che sarà salvato:''</font>
 
  <FONT color=gray>' ''Imposta il percorso ed il nome del file wav che sarà salvato:''</font>
  wav = Alloc("''percorso/del/file.wav''")
+
  wav = Alloc("<FONT color=gray>''/percorso/del/file.wav''</font>")
 
  local_text = testo
 
   
 
  text_remaining = Len(String@(local_text)) + 1
 
 
   
 
   
   common = pico_sysGetCommon(picoSystem)
+
  text_remaining = Len(String@(testo)) + 1
 +
    
 +
  common = pico_sysGetCommon(picoSystem)
 
      
 
      
 
  <FONT color=gray>' ''Apre il file wav:''</font>
 
  <FONT color=gray>' ''Apre il file wav:''</font>
    picoos_sdfOpenOut(common, VarPtr(sdOutFile), wav, SAMPLE_FREQ_16KHZ, FORMAT_TAG_LIN)
+
  picoos_sdfOpenOut(common, VarPtr(sdOutFile), wav, SAMPLE_FREQ_16KHZ, FORMAT_TAG_LIN)
 
      
 
      
    outBytesPut = Alloc(SizeOf(gb.Short))
+
  outBytesPut = Alloc(SizeOf(gb.Short))
+
 
    While text_remaining
+
  buffer = New Byte[bufferSize]
     
+
 
 +
  obr = frequenza * 16 * canali
 +
 
 +
  While text_remaining    
 
  <FONT color=gray>' ''Invia i dati al motore di sintetizzazione Pico:''</font>
 
  <FONT color=gray>' ''Invia i dati al motore di sintetizzazione Pico:''</font>
      ret = pico_putTextUtf8(picoEngine, testo, text_remaining, outBytesPut)
+
    ret = pico_putTextUtf8(picoEngine, testo, text_remaining, outBytesPut)
      bytes_sent = Short@(outBytesPut)
+
    bytes_sent = Short@(outBytesPut)
      text_remaining -= bytes_sent
+
    text_remaining -= bytes_sent
+
   
     
 
 
  <FONT color=gray>' ''Ciclo per inserire i campioni audio nel buffer:''</font>
 
  <FONT color=gray>' ''Ciclo per inserire i campioni audio nel buffer:''</font>
      Do
+
    Do  
+
      getstatus = pico_getData(picoEngine, outbuf, MAX_OUTBUF_SIZE, VarPtr(bytes_recv), VarPtr(out_data_type))
        getstatus = pico_getData(picoEngine, outbuf, MAX_OUTBUF_SIZE, VarPtr(bytes_recv), VarPtr(out_data_type))
+
      st = Memory outbuf For Write
+
      buffer.Read(st, 0, bytes_recv)
        picoos_sdfPutSamples(sdOutFile, bufused / 2, buffer)
+
      st.Close
        bufused = 0
 
        memcpy(buffer, outbuf, bytes_recv)
 
        bufused += bytes_recv
 
 
 
  <FONT color=gray>' ''Gli stessi dati vengono inviati ad Alsa per consentire l'ascolto immediato del testo:''</font>
 
  <FONT color=gray>' ''Gli stessi dati vengono inviati ad Alsa per consentire l'ascolto immediato del testo:''</font>
        frames = snd_pcm_writei(handle, buffer, bufused / SizeOf(gb.Integer))
+
      frames = snd_pcm_writei(handle, buffer.Data, bytes_recv / SizeOf(gb.Integer))
        If (frames < 0) Then Error.Raise("Errore alla funzione 'snd_pcm_writei': " & snd_strerror(err))
+
      If (frames < 0) Then Error.Raise("Errore alla funzione 'snd_pcm_writei': " & snd_strerror(err))  
 
+
      Write #File.Out, "\rTempo trascorso: " & Date(0, 0, 0, 0, 0, 0, ((letti * 8) / obr) * 1000)
       Loop While PICO_STEP_BUSY = getstatus
+
       letti += bytes_recv
     
+
    Loop While PICO_STEP_BUSY = getstatus
    Wend
+
  Wend
 
      
 
      
 
  <FONT color=gray>' ''Chiude il file wav:''</font>
 
  <FONT color=gray>' ''Chiude il file wav:''</font>
    picoos_sdfCloseOut(common, VarPtr(sdOutFile))
+
  picoos_sdfCloseOut(common, VarPtr(sdOutFile))
 
   
 
   
 
  <FONT color=gray>' ''Chiude l'handle della libreria Alsa:''</font>
 
  <FONT color=gray>' ''Chiude l'handle della libreria Alsa:''</font>
    snd_pcm_close(handle)
+
  snd_pcm_close(handle)
 
 
 
    
 
    
 
  <FONT color=gray>' ''Chiude infine anche tutte le risorse della libreria "libttspico":''</font>
 
  <FONT color=gray>' ''Chiude infine anche tutte le risorse della libreria "libttspico":''</font>
+
  If picoEngine > 0 Then
    If IsNull(picoEngine) = False Then
+
    pico_disposeEngine(picoSystem, VarPtr(picoEngine))
      pico_disposeEngine(picoSystem, VarPtr(picoEngine))
+
    pico_releaseVoiceDefinition(picoSystem, PICO_VOICE_NAME)
      pico_releaseVoiceDefinition(picoSystem, PICO_VOICE_NAME)
+
    picoEngine = 0
      picoEngine = Null
+
  Endif
    Endif
 
 
      
 
      
    If IsNull(picoSgResource) = False Then
+
  If picoSgResource > 0 Then
      pico_unloadResource(picoSystem, VarPtr(picoSgResource))
+
    pico_unloadResource(picoSystem, VarPtr(picoSgResource))
      picoSgResource = Null
+
    picoSgResource = 0
    Endif
+
  Endif
 
      
 
      
    If IsNull(picoTaResource) = False Then
+
  If picoTaResource > 0 Then
      pico_unloadResource(picoSystem, VarPtr(picoTaResource))
+
    pico_unloadResource(picoSystem, VarPtr(picoTaResource))
      picoTaResource = Null
+
    picoTaResource = 0
    Endif
+
  Endif
+
 
    If IsNull(picoSystem) = False Then
+
  If picoSystem > 0 Then
      pico_terminate(VarPtr(picoSystem))
+
    pico_terminate(VarPtr(picoSystem))
      picoSystem = Null
+
    picoSystem = 0
    Endif
+
  Endif
 
      
 
      
 
  <FONT color=gray>' ''Libera la memoria allocata:''</font>
 
  <FONT color=gray>' ''Libera la memoria allocata:''</font>
    Free(outBytesPut)
+
  Free(outBytesPut)
    Free(wav)
+
  Free(wav)
    Free(picoMemArea)
+
  Free(picoMemArea)
    Free(picoTaResourceName)
+
  Free(picoTaResourceName)
    Free(picoSgResourceName)
+
  Free(picoSgResourceName)
    Free(outbuf)
+
  Free(outbuf)
    Free(buffer)
+
  Free(testo)
    Free(testo)
 
 
   
 
   
 
  '''End'''
 
  '''End'''

Versione attuale delle 18:43, 6 dic 2021

La tecnologia di sintesi vocale TTS (Text-To-Speech), ossia "dal Testo al Parlato", consente di leggere con una voce umana sintetizzata un testo scritto, riproducendo così i suoni corrispondenti al testo.

Le risorse della libreria di Pico TSS consentono di ottenere tale risultato, ed in particolare di leggere testo di sei fonemi diversi: inglese americano, inglese britannico, tedesco, spagnolo, francese ed italiano.

Per poter utilizzare tali risorse di Pico TSS bisognerà installare nel proprio sistema la libreria condivisa: "libttspico.so.0.0.0 ".


Mostriamo di seguito un semplice esempio, nel quale si sottoporrà alla conversione di sintesi vocale un breve testo in italiano. In particolare il codice riprodurrà vocalmente il testo in un file WAV, nonché, utilizzando le fondamentali funzioni di ALSA, consentirà di ascoltare immediatamente quanto scritto nel testo.

Library "libttspico:0.0.0"

Private Const MAX_OUTBUF_SIZE As Byte = 128
Private Const PICO_MEM_SIZE As Integer = 2500000
Private Const PICO_MAX_DATAPATH_NAME_SIZE As Byte = 128
Private Const PICO_MAX_FILE_NAME_SIZE As Byte = 64
Private Const PICO_LINGWARE_PATH As String = "/usr/share/pico/lang/"
Private Const PICO_MAX_RESOURCE_NAME_SIZE As Byte = 32
Private Const PICO_VOICE_NAME As String = "PicoVoice"
Private Const PICO_STEP_IDLE As Byte = 200                  ' No more input text available in the Pico text input buffer
Private Const PICO_STEP_BUSY As Byte = 201                  ' Process input and producing speech output
Private Const PICO_STEP_ERROR As Short = -200           
Private Const PICO_EXC_UNEXPECTED_FILE_TYPE As Short = -41
Private Const SAMPLE_FREQ_16KHZ As Integer = 16000
Private Const FORMAT_TAG_LIN As Byte = 1                    ' linear 16 - bit encoding
Private Const SND_PCM_STREAM_PLAYBACK As Byte = 0
Private Const SND_PCM_FORMAT_S16_LE As Byte = 2
Private Const SND_PCM_ACCESS_RW_INTERLEAVED As Byte = 3
Private Const nomen As String = "default"
Private picoInternalTaLingware As String[] = ["en-US_ta.bin", "en-GB_ta.bin", "de-DE_ta.bin", "es-ES_ta.bin", "fr-FR_ta.bin", "it-IT_ta.bin"]
Private picoInternalSgLingware As String[] = ["en-US_lh0_sg.bin", "en-GB_kh0_sg.bin", "de-DE_gl0_sg.bin", "es-ES_zl0_sg.bin", "fr-FR_nk0_sg.bin", "it-IT_cm0_sg.bin"]
 
' int pico_initialize(void *memory, const pico_Uint32 size, pico_System *outSystem)
' Initializes the Pico system and returns its handle in 'outSystem'.
Private Extern pico_initialize(memP As Pointer, size As Integer, outSystem As Pointer) As Integer

' int pico_loadResource(pico_System system, const pico_Char *resourceFileName, pico_Resource *outResource)
' Loads a resource file into the Pico system.
Private Extern pico_loadResource(pico_System As Pointer, resFileName$ As String, pico_Resource As Pointer) As Integer

' int pico_getResourceName(pico_System system, pico_Resource resource, pico_Retstring outName)
' Gets the unique resource name of a loaded resource.
Private Extern pico_getResourceName(pico_System As Pointer, pico_Resource As Pointer, outName As Pointer) As Integer

' int pico_createVoiceDefinition(pico_System system, const pico_Char *voiceName)
' Creates a voice definition.
Private Extern pico_createVoiceDefinition(pico_System As Pointer, voiceName As String) As Integer

' int pico_addResourceToVoiceDefinition(pico_System system, const pico_Char *voiceName, const pico_Char *resourceName)
' Adds a mapping pair ('voiceName', 'resourceName') to the voice definition.
Private Extern pico_addResourceToVoiceDefinition(pico_System As Pointer, voiceName As String, resourceName As Pointer) As Integer

' int pico_newEngine(pico_System system, const pico_Char *voiceName, pico_Engine *outEngine)
' Creates and initializes a new Pico engine instance and returns its handle in 'outEngine'.
Private Extern pico_newEngine(pico_System As Pointer, voiceName As String, outEngine As Pointer) As Integer

' picoos_Common pico_sysGetCommon(pico_System this)
Private Extern pico_sysGetCommon(pico_System As Pointer) As Pointer

' picoos_bool picoos_sdfOpenOut (picoos_Common g, picoos_SDFile * sdFile, picoos_char fileName[], int sf, picoos_encoding_t enc)
Private Extern picoos_sdfOpenOut(commP As Pointer, sdFile As Pointer, fileName As Pointer, sf As Integer, enc As Byte) as Boolean

' picoos_bool picoos_sdfCloseOut (picoos_Common g, picoos_SDFile * sdFile)
Private Extern picoos_sdfCloseOut(commP As Pointer, sdFile As Pointer) as Boolean

' int pico_putTextUtf8(pico_Engine engine, const pico_Char *text, const pico_Int16 textSize, pico_Int16 *outBytesPut)
' Puts text 'text' encoded in UTF8 into the Pico text input buffer
Private Extern pico_putTextUtf8(outEngine As Pointer, texP As Pointer, textsize As Short, outBytesPut As Pointer) As Integer

' int pico_getData(pico_Engine engine, void *outBuffer, const pico_Int16 bufferSize, pico_Int16 *outBytesReceived, pico_Int16 *outDataType)
' Gets speech data from the engine
Private Extern pico_getData(engine As Pointer, outBuffer As Pointer, bufferSize As Short, outBytesReceived As Pointer, outDataType As Pointer) As Integer
 
' pico_disposeEngine(pico_System system, pico_Engine *inoutEngine)
' Disposes a Pico engine and releases all memory it occupied.
Private Extern pico_disposeEngine(pico_System As Pointer, inoutEngine As Pointer)

' pico_releaseVoiceDefinition(pico_System system, const pico_Char *voiceName)
' Releases the voice definition 'voiceName'.
Private Extern pico_releaseVoiceDefinition(pico_System As Pointer, voiceName As String)

' pico_unloadResource(pico_System system, pico_Resource *inoutResource)
' Unloads a resource file from the Pico system.
Private Extern pico_unloadResource(pico_System As Pointer, inoutResource As Pointer)

' pico_terminate(pico_System *system)
' Terminates the Pico system.
Private Extern pico_terminate(pico_System As Pointer)


Library "libasound:2"

' int snd_pcm_open(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode)
' Opens a PCM.
Private Extern snd_pcm_open(pcmP As Pointer, nome As String, stream As Integer, mode As Integer) As Integer

' const char * snd_strerror (int errnum)
' Returns the message For an Error code.
Private Extern snd_strerror(errnum As Integer) As String

' int snd_pcm_set_params (snd_pcm_t *pcm, snd_pcm_format_t format, snd_pcm_access_t access, unsigned int canali, unsigned int rate, int soft_resample, unsigned int latency)
' Set the hardware And software parameters
Private Extern snd_pcm_set_params(pcmP As Pointer, formatB As Byte, accessB As Byte, canali As Integer, rate As Integer, soft_resample As Integer, latency As Integer) As Integer
 
' snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
' Write interleaved frames to a PCM.
Private Extern snd_pcm_writei(pcmP As Pointer, buffP As Pointer, uframes As Long) As Integer

' int snd_pcm_close(snd_pcm_t **pcm)
' Close PCM handle.
Private Extern snd_pcm_close(pcmP As Pointer)
 

Public Sub Main()

 Dim picoMemArea, picoSystem As Pointer
 Dim picoTaResource, picoSgResource, picoTaResourceName As Pointer
 Dim picoSgResourceName, picoEngine, common, outBytesPut As Pointer
 Dim testo, wav, sdOutFile, outbuf, handle As Pointer
 Dim buffer As Byte[]
 Dim resourceFileName, picoSgFileName As String
 Dim buffersize As Short = 256
 Dim ret, getstatus, err, obr, frames, letti As Integer
 Dim st As Stream
 Dim bytes_sent, bytes_recv, text_remaining, out_data_type As Short
 Dim frequenza As Integer = 8000
 Dim canali As Byte = 2

' Apre il sub-sistema PCM di ALSA e gli passa dei valori per i parametri della riproduzione audio:
 err = snd_pcm_open(VarPtr(handle), nomen, SND_PCM_STREAM_PLAYBACK, 0)
 If err < 0 Then Error.Raise("Errore nell'apertura dell'interfaccia PCM di Alsa: " & snd_strerror(err))

 err = snd_pcm_set_params(handle, SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, canali, frequenza, 1, 500000)
 If err < 0 Then Error.Raise("Errore nell'impostazione dei parametri dell'interfaccia PCM di Alsa: " & snd_strerror(err))
    
' Impostiamo il testo, al quale applicare la sintesi vocale:
 testo = Alloc("www.gambas-it.org è il sito della comunità italiana dei programmatori Gambas.")
 
 outbuf = Alloc(CInt(MAX_OUTBUF_SIZE / 2))
   
 picoMemArea = Alloc(PICO_MEM_SIZE)
   
' Inizializza la libreria 'libttspico':
 ret = pico_initialize(picoMemArea, PICO_MEM_SIZE, VarPtr(picoSystem))
 If ret < 0 Then Error.Raise("Impossibile inizializzare la libreria 'libttspico' !")

' Carica il file lingware di risorse di analisi del testo.
' Per modificare la lingua di sintesi, cambiare il valore dell'indice della variabile "picoInternalTaLingware[]":
 resourceFileName = PICO_LINGWARE_PATH & picoInternalTaLingware[5]

 ret = pico_loadResource(picoSystem, resourceFileName, VarPtr(picoTaResource)) 
 If ret < 0 Then Error.Raise("Errore alla funzione 'pico_loadResource' !")
   
' Carica il file lingware di risorse di generazione del segnale.
' Per modificare la lingua di sintesi, cambiare il valore dell'indice della variabile "picoInternalSgLingware[]":
 picoSgFileName = PICO_LINGWARE_PATH & picoInternalSgLingware[5]
   
 ret = pico_loadResource(picoSystem, picoSgFileName, VarPtr(picoSgResource))
      
' Ottiene il nome della risorsa di analisi del testo:
 picoTaResourceName = Alloc(SizeOf(gb.Byte), PICO_MAX_RESOURCE_NAME_SIZE)
   
 ret = pico_getResourceName(picoSystem, picoTaResource, picoTaResourceName)
  
' Ottiene il nome della risorsa di generazione del segnale:
 picoSgResourceName = Alloc(SizeOf(gb.Byte), PICO_MAX_RESOURCE_NAME_SIZE)
   
 ret = pico_getResourceName(picoSystem, picoSgResource, picoSgResourceName)
  
' Crea una definizione vocale:
 ret = pico_createVoiceDefinition(picoSystem, PICO_VOICE_NAME)

' Aggiunge alla voce la risorsa di analisi del testo:
 ret = pico_addResourceToVoiceDefinition(picoSystem, PICO_VOICE_NAME, picoTaResourceName)

' Aggiunge alla voce la risorsa di generazione del segnale:
 ret = pico_addResourceToVoiceDefinition(picoSystem, PICO_VOICE_NAME, picoSgResourceName)

' Crea a nuovo motore di sintetizzazione Pico:
 ret = pico_newEngine(picoSystem, PICO_VOICE_NAME, VarPtr(picoEngine))

' Imposta il percorso ed il nome del file wav che sarà salvato:
 wav = Alloc("/percorso/del/file.wav")

 text_remaining = Len(String@(testo)) + 1
  
 common = pico_sysGetCommon(picoSystem)
   
' Apre il file wav:
 picoos_sdfOpenOut(common, VarPtr(sdOutFile), wav, SAMPLE_FREQ_16KHZ, FORMAT_TAG_LIN)
    
 outBytesPut = Alloc(SizeOf(gb.Short))
  
 buffer = New Byte[bufferSize]
  
 obr = frequenza * 16 * canali
  
 While text_remaining     
' Invia i dati al motore di sintetizzazione Pico:
   ret = pico_putTextUtf8(picoEngine, testo, text_remaining, outBytesPut)
   bytes_sent = Short@(outBytesPut)
   text_remaining -= bytes_sent
    
' Ciclo per inserire i campioni audio nel buffer:
   Do   
     getstatus = pico_getData(picoEngine, outbuf, MAX_OUTBUF_SIZE, VarPtr(bytes_recv), VarPtr(out_data_type))
     st = Memory outbuf For Write
     buffer.Read(st, 0, bytes_recv)
     st.Close
' Gli stessi dati vengono inviati ad Alsa per consentire l'ascolto immediato del testo:
     frames = snd_pcm_writei(handle, buffer.Data, bytes_recv / SizeOf(gb.Integer))
     If (frames < 0) Then Error.Raise("Errore alla funzione 'snd_pcm_writei': " & snd_strerror(err))    
     Write #File.Out, "\rTempo trascorso: " & Date(0, 0, 0, 0, 0, 0, ((letti * 8) / obr) * 1000)
     letti += bytes_recv
   Loop While PICO_STEP_BUSY = getstatus
 Wend
   
' Chiude il file wav:
 picoos_sdfCloseOut(common, VarPtr(sdOutFile))

' Chiude l'handle della libreria Alsa:
 snd_pcm_close(handle)
 
' Chiude infine anche tutte le risorse della libreria "libttspico":
 If picoEngine > 0 Then
   pico_disposeEngine(picoSystem, VarPtr(picoEngine))
   pico_releaseVoiceDefinition(picoSystem, PICO_VOICE_NAME)
   picoEngine = 0
 Endif
   
 If picoSgResource > 0 Then
   pico_unloadResource(picoSystem, VarPtr(picoSgResource))
   picoSgResource = 0
 Endif
   
 If picoTaResource > 0 Then
   pico_unloadResource(picoSystem, VarPtr(picoTaResource))
   picoTaResource = 0
 Endif
  
 If picoSystem > 0 Then
   pico_terminate(VarPtr(picoSystem))
   picoSystem = 0
 Endif
   
' Libera la memoria allocata:
 Free(outBytesPut)
 Free(wav)
 Free(picoMemArea)
 Free(picoTaResourceName)
 Free(picoSgResourceName)
 Free(outbuf)
 Free(testo)

End


Riferimenti