Beispiel #1
0
    void OnGUI()
    {
        KitchenSink.OnGUIBack();

        // display the currently speaking text
        GUI.Label(new Rect(50, 50, Screen.width - 100, Screen.height / 4 - 60), speakingText, labelStyle);

        // ask for input
        inputText = GUI.TextField(new Rect(50, Screen.height / 4, (float)(Screen.width * 0.8 - 50), 80), inputText);

        // speak the input text
        if (GUI.Button(new Rect((float)(Screen.width * 0.8), Screen.height / 4, (float)(Screen.width * 0.2 - 50), 80), "Speak"))
        {
            SpeechXT.settings.pitchMultiplier = pitchValue;
            SpeechXT.settings.rate            = speedValue;
            SpeechXT.settings.volume          = volumeValue;
            SpeechXT.settings.voice           = AVSpeechSynthesisVoice.Voice(comboBoxList[selectedItemIndex].text);
            SpeechXT.Speak(inputText);
        }

        // combo box for selecting languages
        GUI.Label(new Rect(50, Screen.height / 4 + 100, 100, 50), "Language");
        selectedItemIndex = comboBoxControl.List(
            new Rect(150, Screen.height / 4 + 100, 100, 50), selectedItemIndex, comboBoxList, listStyle);


        GUILayout.BeginArea(new Rect(50, Screen.height / 4 + 200, Screen.width / 2 - 100, Screen.height / 4 * 3 - 250));

        // manually change pitch, speed, and volume
        pitchValue = GUILayout.HorizontalSlider(pitchValue, 0.5f, 2.0f);
        GUILayout.Label("Pitch: " + pitchValue, GUILayout.ExpandHeight(true));

        speedValue = GUILayout.HorizontalSlider(speedValue, 0.0f, 1.0f);
        GUILayout.Label("Speed: " + speedValue, GUILayout.ExpandHeight(true));

        volumeValue = GUILayout.HorizontalSlider(volumeValue, 0.0f, 1.0f);
        GUILayout.Label("Volume: " + volumeValue, GUILayout.ExpandHeight(true));

        GUILayout.EndArea();


        // predefined examples in different languages
        GUI.Label(new Rect(Screen.width / 4 * 3 - 50, Screen.height / 4 + 100, 100, 50), "Examples");

        GUILayout.BeginArea(new Rect(Screen.width / 2 + 50, Screen.height / 4 + 150, Screen.width / 4 - 60, Screen.height / 4 * 3 - 200));

        if (GUILayout.Button("American English", GUILayout.ExpandHeight(true)))
        {
            SpeechXT.settings.pitchMultiplier = 1f;
            SpeechXT.settings.rate            = 0.25f;
            SpeechXT.settings.volume          = 1f;
            SpeechXT.settings.voice           = AVSpeechSynthesisVoice.Voice("en-US");
            SpeechXT.Speak("Hello, I have Siri's voice.");
        }

        if (GUILayout.Button("Mexican Spanish", GUILayout.ExpandHeight(true)))
        {
            SpeechXT.settings.voice = AVSpeechSynthesisVoice.Voice("es-MX");
            SpeechXT.Speak("Buenos días");
        }

        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(Screen.width / 4 * 3 + 10, Screen.height / 4 + 150, Screen.width / 4 - 60, Screen.height / 4 * 3 - 200));

        if (GUILayout.Button("Aussie", GUILayout.ExpandHeight(true)))
        {
            SpeechXT.settings.voice = AVSpeechSynthesisVoice.Voice("en-AU");
            SpeechXT.Speak("Good day, mate.");
        }

        if (GUILayout.Button("French", GUILayout.ExpandHeight(true)))
        {
            SpeechXT.settings.voice = AVSpeechSynthesisVoice.Voice("fr-FR");
            SpeechXT.Speak("bonjour, mon amour.");
        }

        GUILayout.EndArea();
    }