# Problems with text to speech

**URL:** <https://forum.ionicframework.com/t/problems-with-text-to-speech/31927>\
**Category:** ionic-v1\
**Created:** [September 7, 2015, 2:21pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927 "2015-09-07T14:21:06Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![soupman99](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@soupman99](https://forum.ionicframework.com/u/soupman99)\
**Post date:** [September 7, 2015, 2:21pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/1 "2015-09-07T14:21:06Z")

</div>

I’m brand new to Ionic, have quite a bit of experience with AngularJS

I’m trying to included a text to speech feature in my app. I used the following plugin:

```
cordova plugin add org.apache.cordova.plugin.tts

```

My desktop browser speaks just fine with:

```
Ionic serve 

```

But when I upload the app to my Samsung GS4 (Ionic run android) it never speaks.

What am I missing?

```
.run(function($ionicPlatform) {
 $ionicPlatform.ready(function() {

if (window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  cordova.plugins.Keyboard.disableScroll(true);

}
//just to to test it out quickly.
var speech = new SpeechSynthesisUtterance('hello world');
speech.lang = 'en-US';
speechSynthesis.speak(speech);

if (window.StatusBar) {
  // org.apache.cordova.statusbar required
  StatusBar.styleDefault();
}

  });
})
```

---

<div class="post-metadata">

**Author:** ![Gajotres](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gajotres/32/98564_2.png) [@Gajotres](https://forum.ionicframework.com/u/Gajotres)\
**Post date:** [September 7, 2015, 2:22pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/2 "2015-09-07T14:22:36Z")

</div>

Have you debugged your app and are you receiving any errors?

---

<div class="post-metadata">

**Author:** ![soupman99](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@soupman99](https://forum.ionicframework.com/u/soupman99)\
**Post date:** [September 7, 2015, 2:36pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/3 "2015-09-07T14:36:17Z")

</div>

I actually just found this plugin which supports both platforms:

> **[vilic/cordova-plugin-tts](https://github.com/vilic/cordova-plugin-tts)**
>
> cordova-plugin-tts - Cordova Text-to-Speech Plugin

I get an “Uncaught ReferenceError: TTS is not defined” error when I put this in my run function:

```
TTS
    .speak('hello, world!', function () {
        alert('success');
    }, function (reason) {
        alert(reason);
    });

```

Do I need to include that second block of text in the read me? I’m not sure how or where to do that…

---

<div class="post-metadata">

**Author:** ![soupman99](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@soupman99](https://forum.ionicframework.com/u/soupman99)\
**Post date:** [September 7, 2015, 3:29pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/4 "2015-09-07T15:29:37Z")

</div>

Got it working. Just needed to add “window”

window.TTS.speak(‘blah blah blah’)

---

<div class="post-metadata">

**Author:** ![sameera207](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sameera207/32/101489_2.png) [@sameera207](https://forum.ionicframework.com/u/sameera207)\
**Post date:** [October 15, 2015, 12:19pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/5 "2015-10-15T12:19:58Z")

</div>

Hi @soupman99,

I’m trying to do the same in my sample app, Following are the things I have done

1 - install `cordova plugin add cordova-plugin-tts`

1. 

```
   .controller('DashCtrl', function($scope) {
    
      window.TTS.speak('blah blah blah', function(){
      }, function(){
      })
    })

```

and I’m getting `Cannot read property 'speak' error`. I’m missing the module name after `$scope` in controller, but I’m not sure what to put there (I tried tts and didnt work)

appreciate if you could point me to right direction, thanks a lot

---

<div class="post-metadata">

**Author:** ![jakama](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jakama/32/92438_2.png) [@jakama](https://forum.ionicframework.com/u/jakama)\
**Post date:** [October 18, 2015, 6:52pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/6 "2015-10-18T18:52:00Z")

</div>

Hello @sameera207,

I has try the same and I has needed to install cordova plugin add cordova-plugin-tts

Then, I has used the next code:

```
    TTS
        .speak({
            text: $scope.color,
            locale: 'es-ES',
            rate: 0.75
        }, function () { alert("success");
    },
    function (reason) {
    });

```

(without window before TTS) and it’s works IN DEVICE not using “ionic serve”. When you use navigator you get an undefined error.

---

<div class="post-metadata">

**Author:** ![sameera207](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sameera207/32/101489_2.png) [@sameera207](https://forum.ionicframework.com/u/sameera207)\
**Post date:** [October 19, 2015, 1:45pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/7 "2015-10-19T13:45:47Z")

</div>

hey @jakama, 👍, it worked… I had to run it in the real phone with your code, thanks a lot

---

<div class="post-metadata">

**Author:** ![Tris](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@Tris](https://forum.ionicframework.com/u/Tris)\
**Post date:** [October 27, 2015, 7:17pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/8 "2015-10-27T19:17:17Z")

</div>

sorry, I can not implement this plugin, someone can show all the steps to succeed?

for now I added the plugin to my project, and copy the code in the controllers, but nothing.

I tried the app on my iOS device, on the browser and on the Android emulator  
I have to do? add the module? where am I wrong?

the error is always “TTS is undefined”.

thanks a lot

---

<div class="post-metadata">

**Author:** ![diegovieira](https://avatars.discourse-cdn.com/v4/letter/d/73ab20/32.png) [@diegovieira](https://forum.ionicframework.com/u/diegovieira)\
**Post date:** [November 17, 2015, 10:05pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/9 "2015-11-17T22:05:00Z")

</div>

try this - keep in mind that this works only while running with an emulator or device

```auto
if (window.cordova) {
        TTS
          .speak({
            text: 'hello world!',
            locale: 'en-GB',
            rate: 1.1
          }, function () {
          }, function (reason) {
          });
    }

```

---

<div class="post-metadata">

**Author:** ![nuruddinba691](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nuruddinba691](https://forum.ionicframework.com/u/nuruddinba691)\
**Post date:** [January 12, 2016, 2:16pm UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/10 "2016-01-12T14:16:05Z")

</div>

this plugin support Arabic language ?

---

<div class="post-metadata">

**Author:** ![Praveen\_07](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@Praveen\_07](https://forum.ionicframework.com/u/Praveen_07)\
**Post date:** [June 15, 2016, 12:35am UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/11 "2016-06-15T00:35:27Z")

</div>

@jakama : Initially I was trying in rippl, later when I deployed my app in mobile it worked 🙂 tested in both Android 5 and 6 working perfectly fine 🙂

---

<div class="post-metadata">

**Author:** ![saravanadsk33](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@saravanadsk33](https://forum.ionicframework.com/u/saravanadsk33)\
**Post date:** [January 20, 2018, 7:27am UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/12 "2018-01-20T07:27:56Z")

</div>

I need proper code files.

---

<div class="post-metadata">

**Author:** ![saravanadsk33](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@saravanadsk33](https://forum.ionicframework.com/u/saravanadsk33)\
**Post date:** [January 20, 2018, 7:57am UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/13 "2018-01-20T07:57:42Z")

</div>

I need code source code.

---

<div class="post-metadata">

**Author:** ![Tues79](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@Tues79](https://forum.ionicframework.com/u/Tues79)\
**Post date:** [March 9, 2018, 9:56am UTC](https://forum.ionicframework.com/t/problems-with-text-to-speech/31927/14 "2018-03-09T09:56:38Z")

</div>

Hi,  
I am trying to use TTS.tts and passing a long string approx 5000 charecters but it it not speaking while shrten the string with less then 4000 charetcerts, it is speaking the text.

$scope.speakText = function(text) {  
console.log(text);  
console.log($scope.data[text]);  
$scope.showSpeakBtn = false;  
$scope.showStopBtn = true;

if (window.cordova) {  
TTS.speak({  
text: $scope.data[text],  
locale: ‘en-US’,  
rate: 1.0  
}, function () {

```
       // Do Something after success

   }, function (reason) {
       // Handle the error case
   });
}

```

}

Please suggest how to resolve this.
