S. Andy S. Andy - 2 months ago 23
AngularJS Question

Angular JS trying add a text to speech function



<ion-view view-title="Call Center" >
<ion-content = "padding">

<div ng-controller="CallCtrl1" class ="callPosition">
<!--button >Broken Lamp</button-->


<p class = "callMessage"> {{jalantol}} </p>
<a href="tel:{{telpon}}" ng-click = "panggil()" class= "button button-positive callButton" >

<p class = "callText"> Call </p>

</a>

</div>
<script>
function play(){
var text = "Keos bat skjadnsakjdnkasjndkjsand"
var url = 'http://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&textlen=32&client=tw-ob&tl=id&q='+text;
var a = new Audio(url);
window.a.play();
}
</script>
</head>
<body>
<button onclick="play();"> Speak it </button>
</body>

</ion-content>
</ion-view>




I'm newbie in ionic and web programming.
I have an ionic project using angular js, when I'm try to add text to speech function, it give an error "ReferenceError: play is not defined[Learn More]".
Anyone have any suggestion?
Thank's before

Answer

You can use speechSynthesis,

 var msg = new SpeechSynthesisUtterance("this is a test");
 window.speechSynthesis.speak(msg);

Working Demo