TTS - Text to Speech - Ein Funktionstest für einen Sprachsynthesizer
(EN google-translate)
(PL google-translate)
Sprachsynth002.zip
Bild 0-1: Screenshot der App.
Hinweise:
  | 
Sollte wegen verändertem Android-Betriebssystem das Flashen neuer Apps nicht funktionieren, kann noch ein Versuch mit adb gemacht werden. Siehe: Android->ADB_apps.
import processing.vr.*;
import android.speech.tts.TextToSpeech;
import java.util.Locale;
import java.util.Set;
import android.media.AudioManager;
import android.content.Context;
//ACHTUNG:
//Android->VR anhaken
PMatrix3D eyeMat = new PMatrix3D();
TTS tts;
String zeichen = "ABCDEFGHIJKLMNOPQRSTUVWXZ";
int RESTZEIT = 0;
String[] AUSWAHL = {"1","2","3"};
int inx=0;
void setup() 
{
    fullScreen(MONO);
    
    tts = new TTS();
    tts.setzeSpechgeschwindigkeit(1.0f);
    tts.setzeStimmhoehe(1.0f);
    tts.setzeLautstaerke(0.8f);        
}
void draw() 
{
  //Standardeinstellungen für unser Arbeiten:
  background(0);
  getEyeMatrix(eyeMat); //Kameramatrix auslesen  
  translate(eyeMat.m03, eyeMat.m13, eyeMat.m23); //Welt in Koordinatenursprung von Kamera setzen.
  lights();
  float ez_x =  eyeMat.m02;  //Einheitsvektor der aktuellen Blickrichtung
//  float ez_y =  -eyeMat.m12;
  float ez_y =  eyeMat.m12;
  float ez_z =  eyeMat.m22;  
  
  //ENDE Standardeinstellungen für unser Arbeiten:
 
  //Buchstaben auf "Platten" zeichnen:
  textSize(64);
  for(int i=0;i<zeichen.length();i++)
  {
      pushMatrix();
      
      float z = -500.0f;
      float y = - 200 + (i/5)*100;
      float x = 100*(i%5) - 200;
      //Nähe zum Zielkreis:
      
      //1) Einheitsvektor bilden:
      float laenge = sqrt(x*x+y*y+z*z);
      float xx=x/laenge;
      float yy=y/laenge;
      float zz=z/laenge;
      
      //2) Skalarprodukt mit Blickrichtung (ez)      
      float sk = xx*ez_x + yy*ez_y + zz*ez_z;
      
      if(sk>0.99f && RESTZEIT==0)
      {
           AUSWAHL[inx]=zeichen.substring(i,i+1);
           inx++;
           inx%=AUSWAHL.length;
           
           if(AUSWAHL[0].equals(AUSWAHL[1]) && AUSWAHL[1].equals(AUSWAHL[2]))
           {
                tts.sprich(AUSWAHL[0]);
                AUSWAHL[0] ="1";
                AUSWAHL[1] ="2";
                AUSWAHL[2] ="3";
           }
           
           RESTZEIT = 30;
      }
      
      translate(x,y,z); 
      noStroke();
/*      
      fill(200.0f,200.0f,200.0f);
      rect(-40, -40, 80, 80);
      translate(0,0,5); 
*/      
      fill(0,255,0);
      text(zeichen.substring(i,i+1),-20,20);
      popMatrix();
      
  }
  
  //Zielkreis zeichnen
  eye(); //Transformation realtiv zur Kamera
  translate(0, 0, 95); //Zielkreis relativ zur Kamera zeichnen
  noFill();
  stroke(255,0,0);
  ellipse(0, 0, 10, 10);
  
  if(RESTZEIT>0)
      RESTZEIT--;
}
Code 0-1: Sprachsynthese002.pde
public class TTS
{
     TextToSpeech tts;
     AudioManager audio;
     int currentVolume;
     int maxVolume;
     public void setzeSpechgeschwindigkeit(float s)
     {
         tts.setSpeechRate(s);    
     }
     public void setzeStimmhoehe(float h)
     {
         tts.setSpeechRate(h);    
     }
     public void setzeLautstaerke(float ls)
     {
         if(ls<0.0f)
             ls=0.0f;
         if(ls>1.0f)
             ls=1.0f;
         int LAUT  = (int) (maxVolume*ls);
             
         audio.setStreamVolume(AudioManager.STREAM_MUSIC, LAUT, 0);             
     }
     public void sprich(String text)
     {
        if(tts!=null)
        {
          tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
          println("tts: \""+text+"\"");
        }  
        else
        {
          println("tts==null");
        }  
     }
     public TTS()
     {
         //NEU:  getActivity(). ab Proc. 3!
         tts=new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
         //@Override
            public void onInit(int status) {
               if(status != TextToSpeech.ERROR) {
                  tts.setLanguage(Locale.GERMAN);
               }
            }
         });
         audio = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);  //NEU:  getActivity(). ab Proc. 3!
         currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
         maxVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
     }
}
Code 0-2: TTS.pde
Übung
  |