How can I make the voice change its speed?

1

I made an app that converts text to speech ... but now I want to change the speed of the voice ... that there are options that make it faster or slower.

This is my Android code

package e.macg.traductor;

import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.Locale;

public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener {

    private TextToSpeech tts;
    private EditText etx;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tts = new TextToSpeech(this,this);
        etx = (EditText)findViewById(R.id.etxescribir);
        btn = (Button)findViewById(R.id.btnreproducir);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                speakOut();
            }

        });

    }

    @Override
    public void onInit(int status) {
        if (status==TextToSpeech.SUCCESS){
            int resultado = tts.setLanguage(Locale.getDefault());
            if (resultado==TextToSpeech.LANG_NOT_SUPPORTED || resultado==TextToSpeech.LANG_MISSING_DATA){
                Log.e("TTS","Este Lenguaje No Es Soportado");
            }else {
                btn.setEnabled(true);
                speakOut();
            }
        }else {
            Log.e("TTS","Inicializacion del lenguaje es FALLIDA");
        }
    }

    private void speakOut() {
        String text=etx.getText().toString();
        tts.speak(text,TextToSpeech.QUEUE_FLUSH,null);
    }
}
    
asked by Mario Neto 12.12.2018 в 07:32
source

1 answer

0

try this line:

tts.setSpeechRate(0.75f);

The data type of the parameter that the setSpeechRate receives is float.

The normal speed would be 1.0f , and the lowest would be 0.1f while the highest would be 2.0f . I leave the link in case you want to document more about the functions of the TTS.

link

    
answered by 12.12.2018 / 07:59
source