Read string and call in java

-4

I would like to know what API I can use in JAVA, for the following scenario, where I have a String with a password, for example, and the program reads String and voice tag. / p>     

asked by anonymous 10.02.2017 / 19:29

2 answers

1

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

Dependency on Maven for latest version (3.5.3) can 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>

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

A working example class:

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 the credential that is created when Text to Speech is enabled in the Bluemix panel.

Example of credentials:

ThisisarepositoryinGithubthathasthe Sorackb / WatsonTextToSpeechSample implementation.

    
14.02.2017 / 20:09
-3

You can simply create methods for this example and use the 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

    
10.02.2017 / 19:36