Differenze tra le versioni di ""Dal testo al parlato" mediante le funzioni esterne del API di Speech-Dispatcher"

Da Gambas-it.org - Wikipedia.
Riga 4: Riga 4:
  
  
Per usare le funzioni esterne del API di ''Speech-Dispatcher'', è necessario richiamare la sua libreria condivisa che attualmente è: "''libspeechd.so.2.3.0''".
+
Per usare le funzioni esterne del API di ''Speech-Dispatcher'', è necessario richiamare la sua libreria condivisa che attualmente è: "''libspeechd.so.2.4.0''".
  
  
 
Mostriamo di seguito un semplice codice per la lettura parlata di un testo in italiano:
 
Mostriamo di seguito un semplice codice per la lettura parlata di un testo in italiano:
  '''Private''' Enum SPD_MODE_SINGLE = 0, SPD_MODE_THREADED
+
  Private Enum SPD_MODE_SINGLE = 0, SPD_MODE_THREADED
  '''Private''' Enum SPD_IMPORTANT = 1, SPD_MESSAGE, SPD_TEXT, SPD_NOTIFICATION, SPD_PROGRESS
+
  Private Enum SPD_IMPORTANT = 1, SPD_MESSAGE, SPD_TEXT, SPD_NOTIFICATION, SPD_PROGRESS
  '''Private''' Enum SPD_MALE1 = 1, SPD_MALE2, SPD_MALE3, SPD_FEMALE1, SPD_FEMALE2, SPD_FEMALE3, SPD_CHILD_MALE, SPD_CHILD_FEMALE
+
  Private Enum SPD_MALE1 = 1, SPD_MALE2, SPD_MALE3, SPD_FEMALE1, SPD_FEMALE2, SPD_FEMALE3, SPD_CHILD_MALE, SPD_CHILD_FEMALE
 
   
 
   
 
   
 
   
  Library "libspeechd:2.3.0"
+
  Library "libspeechd:2.4.0"
 
   
 
   
 
  <FONT color=gray>' ''SPDConnection* spd_open(char* client_name, char* connection_name, char* user_name, SPDConnectionMode connection_mode)''
 
  <FONT color=gray>' ''SPDConnection* spd_open(char* client_name, char* connection_name, char* user_name, SPDConnectionMode connection_mode)''
 
  ' Opens a new connection to Speech Dispatcher and returns a socket file descriptor you will use to communicate with Speech Dispatcher.''</font>
 
  ' Opens a new connection to Speech Dispatcher and returns a socket file descriptor you will use to communicate with Speech Dispatcher.''</font>
  '''Private''' Extern spd_open(client_name As String, connection_name As String, user_name As String, connection_mode As Integer) As Pointer
+
  Private Extern spd_open(client_name As String, connection_name As String, user_name As String, connection_mode As Integer) As Pointer
 
   
 
   
 
  <FONT color=gray>' ''int spd_set_voice_type(SPDConnection* connection, SPDVoiceType voice)''
 
  <FONT color=gray>' ''int spd_set_voice_type(SPDConnection* connection, SPDVoiceType voice)''
 
  ' ''Set a preferred symbolic voice.''
 
  ' ''Set a preferred symbolic voice.''
 
  ' ''"voice" is one of the following values: SPD_MALE1, SPD_MALE2, SPD_MALE3, SPD_FEMALE1, SPD_FEMALE2, SPD_FEMALE3, SPD_CHILD_MALE, SPD_CHILD_FEMALE''</font>
 
  ' ''"voice" is one of the following values: SPD_MALE1, SPD_MALE2, SPD_MALE3, SPD_FEMALE1, SPD_FEMALE2, SPD_FEMALE3, SPD_CHILD_MALE, SPD_CHILD_FEMALE''</font>
  '''Private''' Extern spd_set_voice_type(connection As Pointer, voice As Integer) As Integer
+
  Private Extern spd_set_voice_type(connection As Pointer, voice As Integer) As Integer
 
    
 
    
 
  <FONT color=gray>' ''int spd_set_synthesis_voice(SPDConnection*, const char *voice_name)''
 
  <FONT color=gray>' ''int spd_set_synthesis_voice(SPDConnection*, const char *voice_name)''
 
  ' ''Set the speech synthesizer voice to use.''</font>
 
  ' ''Set the speech synthesizer voice to use.''</font>
  '''Private''' Extern spd_set_synthesis_voice(connection As Pointer, voice_name As String) As Integer
+
  Private Extern spd_set_synthesis_voice(connection As Pointer, voice_name As String) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int spd_set_language(SPDConnection* connection, char* language)''
 
  <FONT color=gray>' ''int spd_set_language(SPDConnection* connection, char* language)''
 
  ' ''Sets the language that should be used for synthesis. "language" is the language code as defined in [http://it.wikipedia.org/wiki/ISO_639 ISO 639] (“cs”, “en”, "it"...).''</font>
 
  ' ''Sets the language that should be used for synthesis. "language" is the language code as defined in [http://it.wikipedia.org/wiki/ISO_639 ISO 639] (“cs”, “en”, "it"...).''</font>
  '''Private''' Extern spd_set_language(connection As Pointer, language As String) As Integer
+
  Private Extern spd_set_language(connection As Pointer, language As String) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int spd_set_volume(SPDConnection* connection, int volume)''
 
  <FONT color=gray>' ''int spd_set_volume(SPDConnection* connection, int volume)''
 
  ' ''Set the volume of the voice and sounds produced by Speech Dispatcher's output modules.''
 
  ' ''Set the volume of the voice and sounds produced by Speech Dispatcher's output modules.''
 
  ' ''"volume" is a number between -100 and +100 which means the lowest and the loudest voice respectively.''</font>
 
  ' ''"volume" is a number between -100 and +100 which means the lowest and the loudest voice respectively.''</font>
  '''Private''' Extern spd_set_volume(connection As Pointer, volume As Integer) As Integer
+
  Private Extern spd_set_volume(connection As Pointer, volume As Integer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int spd_set_voice_rate(SPDConnection* connection, int rate)''
 
  <FONT color=gray>' ''int spd_set_voice_rate(SPDConnection* connection, int rate)''
 
  ' ''Set voice speaking rate. "rate" is a number between -100 and +100 which means the slowest and the fastest speech rate respectively.''</font>
 
  ' ''Set voice speaking rate. "rate" is a number between -100 and +100 which means the slowest and the fastest speech rate respectively.''</font>
  '''Private''' Extern spd_set_voice_rate(connection As Pointer, rateInt As Integer) As Integer
+
  Private Extern spd_set_voice_rate(connection As Pointer, rateInt As Integer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int spd_set_voice_pitch(SPDConnection* connection, int pitch)''
 
  <FONT color=gray>' ''int spd_set_voice_pitch(SPDConnection* connection, int pitch)''
 
  ' ''Set voice pitch. "pitch" is a number between -100 and +100, which means the lowest and the highest pitch respectively.''</font>
 
  ' ''Set voice pitch. "pitch" is a number between -100 and +100, which means the lowest and the highest pitch respectively.''</font>
  '''Private''' Extern spd_set_voice_pitch(connection As Pointer, pitch As Integer) As Integer
+
  Private Extern spd_set_voice_pitch(connection As Pointer, pitch As Integer) As Integer
 
   
 
   
 
  <FONT color=gray>' ''int spd_sayf(SPDConnection* connection, SPDPriority priority, char* format, ...)''
 
  <FONT color=gray>' ''int spd_sayf(SPDConnection* connection, SPDPriority priority, char* format, ...)''
 
  ' ''Sends a message to Speech Dispatcher.''</font>
 
  ' ''Sends a message to Speech Dispatcher.''</font>
  '''Private''' Extern spd_say(connection As Pointer, priority As Byte, $format As String) As Integer
+
  Private Extern spd_say(connection As Pointer, priority As Byte, $format As String) As Integer
 
   
 
   
 
  <FONT color=gray>' ''void spd_close(SPDConnection *connection)''
 
  <FONT color=gray>' ''void spd_close(SPDConnection *connection)''
 
  ' ''Closes a Speech Dispatcher socket connection, terminates associated threads (if necessary) and frees the memory allocated by spd_open().''</font>
 
  ' ''Closes a Speech Dispatcher socket connection, terminates associated threads (if necessary) and frees the memory allocated by spd_open().''</font>
  '''Private''' Extern spd_close(connection As Pointer)
+
  Private Extern spd_close(connection As Pointer)
 
   
 
   
 
   
 
   
Riga 102: Riga 102:
 
  <FONT color=gray>' ''Potrebbe rendersi necessaria la chiusura del processo di "speech-dispatcher"''
 
  <FONT color=gray>' ''Potrebbe rendersi necessaria la chiusura del processo di "speech-dispatcher"''
 
  ' ''prima di effettuare una nuova esecuzione parlata del testo:''</font>
 
  ' ''prima di effettuare una nuova esecuzione parlata del testo:''</font>
   Shell "killall speech-dispatcher"
+
   Shell "killall speech-dispatcher" Wait
+
    
   Wait 0.1
 
 
 
   parla()
 
   parla()
 
   
 
   
Riga 113: Riga 111:
  
 
=Riferimenti=
 
=Riferimenti=
* Il sito del [http://wahelper.brailcom.org/doc/speechd/speech-dispatcher.html API di ''Speech-Dispatcher'']
+
* http://devel.freebsoft.org/speechd
 +
* http://wahelper.brailcom.org/?p=speechd;a=summary

Versione delle 19:14, 17 nov 2015

Speech-Dispatcher è una risorsa per la sintesi vocale che fornisce una interfaccia comune di facile utilizzo sia per applicazioni client (programmi creati per parlare) sia per i sintetizzatori software effettivamente in grado di convertire il testo in parlato. Tale interfaccia comune generale consente ai programmatori di applicazioni client di avere un modo semplice per l'uso di un software di sintesi vocale evitando così di preoccuparsi di particolari dettagli riguardo ai vari sintetizzatori.

Ogni client (applicazione creata per parlare) apre una connessione socket con Speech-Dispatcher e chiama le funzioni di questo. Quando i messaggi testuali arrivano a Speech-Dispatcher, tale dispositivo li analizza, ne legge il testo da pronunciarsi e lo pone in una delle diverse code in base alla priorità del messaggio e ad altri criteri. Quindi esso decide quando, con quali parametri (impostati dal cliente e dall'utente), e su quale sintetizzatore dirà il messaggio. Queste richieste sono gestite dal plug-in (moduli di output) in uscita ai diversi sintetizzatori hardware e software e poi dette ad alta voce.


Per usare le funzioni esterne del API di Speech-Dispatcher, è necessario richiamare la sua libreria condivisa che attualmente è: "libspeechd.so.2.4.0".


Mostriamo di seguito un semplice codice per la lettura parlata di un testo in italiano:

Private Enum SPD_MODE_SINGLE = 0, SPD_MODE_THREADED
Private Enum SPD_IMPORTANT = 1, SPD_MESSAGE, SPD_TEXT, SPD_NOTIFICATION, SPD_PROGRESS
Private Enum SPD_MALE1 = 1, SPD_MALE2, SPD_MALE3, SPD_FEMALE1, SPD_FEMALE2, SPD_FEMALE3, SPD_CHILD_MALE, SPD_CHILD_FEMALE


Library "libspeechd:2.4.0"

' SPDConnection* spd_open(char* client_name, char* connection_name, char* user_name, SPDConnectionMode connection_mode)
' Opens a new connection to Speech Dispatcher and returns a socket file descriptor you will use to communicate with Speech Dispatcher.
Private Extern spd_open(client_name As String, connection_name As String, user_name As String, connection_mode As Integer) As Pointer

' int spd_set_voice_type(SPDConnection* connection, SPDVoiceType voice)
' Set a preferred symbolic voice.
' "voice" is one of the following values: SPD_MALE1, SPD_MALE2, SPD_MALE3, SPD_FEMALE1, SPD_FEMALE2, SPD_FEMALE3, SPD_CHILD_MALE, SPD_CHILD_FEMALE
Private Extern spd_set_voice_type(connection As Pointer, voice As Integer) As Integer
 
' int spd_set_synthesis_voice(SPDConnection*, const char *voice_name)
' Set the speech synthesizer voice to use.
Private Extern spd_set_synthesis_voice(connection As Pointer, voice_name As String) As Integer

' int spd_set_language(SPDConnection* connection, char* language)
' Sets the language that should be used for synthesis. "language" is the language code as defined in ISO 639 (“cs”, “en”, "it"...).
Private Extern spd_set_language(connection As Pointer, language As String) As Integer

' int spd_set_volume(SPDConnection* connection, int volume)
' Set the volume of the voice and sounds produced by Speech Dispatcher's output modules.
' "volume" is a number between -100 and +100 which means the lowest and the loudest voice respectively.
Private Extern spd_set_volume(connection As Pointer, volume As Integer) As Integer

' int spd_set_voice_rate(SPDConnection* connection, int rate)
' Set voice speaking rate. "rate" is a number between -100 and +100 which means the slowest and the fastest speech rate respectively.
Private Extern spd_set_voice_rate(connection As Pointer, rateInt As Integer) As Integer

' int spd_set_voice_pitch(SPDConnection* connection, int pitch)
' Set voice pitch. "pitch" is a number between -100 and +100, which means the lowest and the highest pitch respectively.
Private Extern spd_set_voice_pitch(connection As Pointer, pitch As Integer) As Integer

' int spd_sayf(SPDConnection* connection, SPDPriority priority, char* format, ...)
' Sends a message to Speech Dispatcher.
Private Extern spd_say(connection As Pointer, priority As Byte, $format As String) As Integer

' void spd_close(SPDConnection *connection)
' Closes a Speech Dispatcher socket connection, terminates associated threads (if necessary) and frees the memory allocated by spd_open().
Private Extern spd_close(connection As Pointer)


Public Sub Form_Open()

  parla()

End


Public Procedure parla()

 Dim conn As Pointer
 Dim err As Integer
 

  conn = spd_open("parla", "main", Null, SPD_MODE_THREADED)

  err = spd_set_voice_type(conn, SPD_MALE1)
  Print err

' Imposta la lingua per la lettura parlata del testo:
  err = spd_set_language(conn, "it")
  Print err
  
  err = spd_set_volume(conn, 100)
  Print err
  
  err = spd_set_voice_rate(conn, -10)
  Print err

  err = spd_set_voice_pitch(conn, -50)
  Print err
 
  err = spd_set_synthesis_voice(conn, "italian")
  Print err

' Si imposta il testo da far leggere ad alta voce:
  err = spd_say(conn, SPD_TEXT, "www.gambas-org.it è la comunità italiana dei programmatori Gambas.")
  Print err

' Chiude la connessione socket:
  spd_close(conn)
 
End


Public Sub Button1_Click()

' Potrebbe rendersi necessaria la chiusura del processo di "speech-dispatcher"
' prima di effettuare una nuova esecuzione parlata del testo:
  Shell "killall speech-dispatcher" Wait
  
  parla()

End


Riferimenti