# How about a GCloud Text-to-Speech & Speech-to-Text wrapper for Processing with a \<10 liner?

**URL:** <https://discourse.processing.org/t/how-about-a-gcloud-text-to-speech-speech-to-text-wrapper-for-processing-with-a-10-liner/15467>\
**Category:** Libraries\
**Created:** [November 13, 2019, 6:35pm UTC](https://discourse.processing.org/t/how-about-a-gcloud-text-to-speech-speech-to-text-wrapper-for-processing-with-a-10-liner/15467 "2019-11-13T18:35:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![advancecoder](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/advancecoder/32/6082_2.png) [@advancecoder](https://discourse.processing.org/u/advancecoder)\
**Post date:** [November 13, 2019, 6:35pm UTC](https://discourse.processing.org/t/how-about-a-gcloud-text-to-speech-speech-to-text-wrapper-for-processing-with-a-10-liner/15467/1 "2019-11-13T18:35:40Z")

</div>

How about a GCloud Text-to-Speech & Speech-to-Text wrapper for Processing with a \<10 liner?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 13, 2019, 8:14pm UTC](https://discourse.processing.org/t/how-about-a-gcloud-text-to-speech-speech-to-text-wrapper-for-processing-with-a-10-liner/15467/2 "2019-11-13T20:14:06Z")

</div>

What do you mean by \<10 liner?  
Code below is from akenaton I believe.

```auto
import android.view.View;
import android.content.Context;
import android.widget.Button;
import android.app.Activity;
import android.view.Gravity;
import android.graphics.Color;
import android.speech.RecognizerIntent;
import android.content.Intent;
import android.widget.Toast;
import java.lang.Throwable;
import java.lang.Exception;
import java.lang.RuntimeException;
import android.content.ActivityNotFoundException;
import java.util.Locale;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.view.View.OnClickListener;
import android.content.Context;
import android.speech.SpeechRecognizer;

Activity act;
Intent intent;
Button bouton;
private static final int MY_BUTTON1 = 9000;
FrameLayout fl;
Context context;

String txt;

void settings() {
  fullScreen();
};

public void onStart() {
  act = this.getActivity();
  context = act.getApplicationContext();

  bouton = new Button(act);
  bouton.setText("Start Speaking");
  bouton.setBackgroundColor(Color.WHITE);
  bouton.setId(MY_BUTTON1);
  OnClickListener oclMonBouton = new OnClickListener() {
    public void onClick(View v) {
      println("Tab here");
      startSpeech();
    }
  };

  bouton.setOnClickListener(oclMonBouton);

  fl = (FrameLayout)act.getWindow().getDecorView().getRootView();
  getActivity().runOnUiThread(new Runnable() {
    //@Override
    public void run() {
      FrameLayout.LayoutParams params1 = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.TOP); 
        fl.addView(bouton, params1);
    }
  });
}

void setup() {

  act = this.getActivity();
}

void draw() {
  fill(255);
  background(0);
  if (txt != null) {
    text(txt, width/2, height/2);
  }
}

private void startSpeech() {
  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  try {
    this.getActivity().startActivityForResult(intent, 666);} 
  catch (ActivityNotFoundException a) {
    Toast.makeText(this.getActivity().getApplicationContext(), "This phone does not support this", 
      Toast.LENGTH_SHORT).show(); }
}

void onActivityResult(int requestCode, int resultCode, Intent data) {
  switch (requestCode) {
  case 666: 
    {
      if (resultCode == Activity.RESULT_OK && null != data) {//data are returned && the phone can use speechToText
        ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        background(255);
        txt = (result.get(0));
        println(txt);
      }
      break;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [November 14, 2019, 10:57am UTC](https://discourse.processing.org/t/how-about-a-gcloud-text-to-speech-speech-to-text-wrapper-for-processing-with-a-10-liner/15467/3 "2019-11-14T10:57:52Z")

</div>

@advancecoder ,@noel ----  
yes that is my code, but as @noel i dont understand “liner”

---

<div class="post-metadata">

**Author:** ![advancecoder](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/advancecoder/32/6082_2.png) [@advancecoder](https://discourse.processing.org/u/advancecoder)\
**Post date:** [November 14, 2019, 2:49pm UTC](https://discourse.processing.org/t/how-about-a-gcloud-text-to-speech-speech-to-text-wrapper-for-processing-with-a-10-liner/15467/4 "2019-11-14T14:49:29Z")

</div>

I meant Google Cloud Text-to-Speech, not Android libraries.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 14, 2019, 3:28pm UTC](https://discourse.processing.org/t/how-about-a-gcloud-text-to-speech-speech-to-text-wrapper-for-processing-with-a-10-liner/15467/5 "2019-11-14T15:28:05Z")

</div>

? Without Android libraries¿ Have you tested the code?  
What do you think they do?  
Edit, I think you mean Cloud SDK.  
@akenaton have worked with that?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 14, 2019, 3:58pm UTC](https://discourse.processing.org/t/how-about-a-gcloud-text-to-speech-speech-to-text-wrapper-for-processing-with-a-10-liner/15467/6 "2019-11-14T15:58:45Z")

</div>

But this is paid.

> **[Cloud Text-to-Speech - Speech Synthesis  |  Cloud Text-to-Speech API
...](https://cloud.google.com/text-to-speech/)**
>
> Cloud Text-to-Speech converts text into 18+ natural-sounding voices, in a variety of languages.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [November 14, 2019, 4:36pm UTC](https://discourse.processing.org/t/how-about-a-gcloud-text-to-speech-speech-to-text-wrapper-for-processing-with-a-10-liner/15467/7 "2019-11-14T16:36:44Z")

</div>

yes i have done that but not with processing, with AS && firebase and i dont know wether it s possible with P5; as for paying that is not absolutely true: GC is free till 4 millions of chars/month.
