Read string and call in java voice

Asked

Viewed 919 times

-4

I wonder which API I can use in JAVA, for the following scenario, where I have a String with a password, for example, and the program read the String and Chava by voice.

  • Try the Freetts

  • I’m taking a look. No more found an implementation example.

  • Here are the demos from Freetts

  • Queria em português.

  • Freetts is a well-known and śolida api for reading text and voice transformation... take a look.. http://freetts.sourceforge.net/docs/index.php

2 answers

1

You can use the service of IBM Bluemix - Watson/Text to Speech. The first million monthly character is free and after that it costs $0.02 per thousand characters. There is a voice referring to Portuguese (Isabela).

Dependence on Maven to the latest version (3.5.3) may be added with the following statement in pom.xml:

<dependency>
    <groupId>com.ibm.watson.developer_cloud</groupId>
    <artifactId>text-to-speech</artifactId>
    <version>3.5.3</version>
</dependency>

Available voices can be found in the documentation Specifying a voice and the formats available in Specifying an audio format.

An example class of operation:

import com.ibm.watson.developer_cloud.http.ServiceCall;
import com.ibm.watson.developer_cloud.text_to_speech.v1.TextToSpeech;
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.AudioFormat;
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice;
import com.ibm.watson.developer_cloud.text_to_speech.v1.util.WaveUtils;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

public class Teste {

  public void sintetizar(String texto) {
    TextToSpeech servico = new TextToSpeech("USUARIO DA CREDENCIAL", "SENHA DA CREDENCIAL");
    Map<String, String> opcoes = new HashMap<String, String>();
    ServiceCall<InputStream> chamada;
    InputStream retorno;
    AudioInputStream tocavel;
    Clip execucao;
    FloatControl volume;

    // Realiza a chamada do serviço
    opcoes.put("accept", "audio/wav;rate=8000");
    servico.setDefaultHeaders(opcoes);
    chamada = servico.synthesize(texto,
            new Voice("pt-BR_IsabelaVoice", null, null),
            new AudioFormat("audio/wav"));
    retorno = chamada.execute(); // Aguarda o retorno

    try {
      tocavel = AudioSystem.getAudioInputStream(WaveUtils.reWriteWaveHeader(retorno));
      execucao = AudioSystem.getClip();
      execucao.open(tocavel);
      execucao.start(); // Inicia a execução do som
      // Aumenta o volume
      volume = (FloatControl) execucao.getControl(FloatControl.Type.MASTER_GAIN);
      volume.setValue(volume.getMaximum());
      execucao.drain(); // Aguarda a execução
      execucao.close(); // Fecha o player
      retorno.close();
    } catch (IOException | LineUnavailableException | UnsupportedAudioFileException ex) {
      Logger.getLogger(Teste.class.getName()).log(Level.SEVERE, null, ex);
    }
  }

  public static void main(String[] args) {
    Teste teste = new Teste();

    teste.sintetizar("Meu texto");
  }
}

The user and password used are those of the credential that is created when the Text to Speech is enabled on the panel of the Bluemix.

Example of credentials:

Exemplo das credenciais

This is a repository on Github that has the implementation Sorackb/WatsonTextToSpeechSample.

  • The Maven dependency for the latest version (3.5.3) can be added with the following statement in pom.xml -- Please tell me how to do this?

  • @Jessésantos did not understand your doubt

  • At this information "The Mave dependency can be added with the following statement", I have to enter this statement? If so, how do I do this? I already created my account, used this test class, changed user and password, and enter the library. Maven jar, but these lines appeared with error: import com.ibm.Watson.developer_cloud.http.Servicecall; Servicecall<Inputstream> call; service.setDefaultHeaders(options); call = service.synthesize(text, new Voice("pt-Br_isabelavoice", null, null), new Audioformat("audio/wav"));

  • @Jessésantos Maven has a configuration file. The pom.xml. But if you’re not familiar with Maven, I advise you to use Watson’s library directly. Here’s the link downloadable.

  • Just add this library?

  • @Jessésantos yes

Show 1 more comment

-3

You can simply create methods for this example and use Audioclip:

public static void main(String[] args){
     String senha = "SENHA123";

     if(senha == "SENHA"){
         executar();
     }
}

public void executar(){
    AudioClip clip = Applet.newAudioClip(urlDoSom);
    clip.start();//toca só uma vez
    clip.loop();//toca o som repetidamente 
    clip.stop();//para de tocar
}

Source: GUJ

  • 3

    I don’t think that answers the question. From what I understand he wants the contents of the string to be played by voice, not to play a sound when comparing the reference of two objects. By the way, how to compare strings in Java.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.