06 August 2020

Text To Speech (TTS) and Audio file with NativeScript

In my game - My first game (game for children), that created with NativeScript, I use audio and speak services.


The NativeScript is platform that use to develop an android (or IOS) app with angular and TypeScript.

Here is the class the use for Audio and Speak with NativeScript.

The speak if Text To Speech (TTS) from google.

The audio is mp3 file

import { TNSTextToSpeechSpeakOptions } from "nativescript-texttospeech";
import { TNSPlayerAudioPlayerOptions } from "nativescript-audio-player";
import * as timer from "tns-core-modules/timer";
import { Injectable } from "@angular/core";
import * as firebase from "nativescript-plugin-firebase";
@Injectable({
  providedIn: "root",
})
export class AudioAndSpeak {
  public audioTrackDurationany;
  public remainingDurationany// used to show the remaining time of the audio track
  private TTS = new TNSTextToSpeech();
  private _playerTNSPlayer;
  public isSpeakingboolean = false;
  constructor() {
    this._player = new TNSPlayer();
    this._player.debug = false;
  }
  public async speak(textstringlocal : string) {
    let isSpeaking = true;
    let  speakRate = 0.8;
    let speakOptionsSpeakOptions = {
      text: text,
      speakRate: speakRate,
      queue: true,
      locale : local,
      finishedCallback: async () => {
        isSpeaking = false;
      },
    };
    this.TTS.speak(speakOptions).then(() => console.log("End Speak"));
    return isSpeaking;
  }
  public async playSound(filePathstringfilePath2?: stringvolume? :number) {
    try {
      if(!volume)
      {
        volume = 1;
      }
      this._player.volume = volume;
      this.isSpeaking = true;
      const playerOptionsAudioPlayerOptions = {
        audioFile: filePath,
        loop: false,        
        completeCallback: async () => {
       
          await this._player.dispose();
          this.isSpeaking = false;          
         // player disposed
          if (filePath2) {
            this.playSound(filePath2);
          }
        },
        errorCallback: (errorObject=> {
          console.log('errorCallback')
          console.log(JSON.stringify(errorObject));
          this.isSpeaking = false;
        },
        infoCallback: (args=> {
          console.log(JSON.stringify(args));
        },
      };
      await this._player.playFromFile(playerOptions).catch((error=> {
        firebase.crashlytics.sendCrashLog('AudioAndSpeak -> playSound playFromFile :' + error);
        console.log(error);
        this.isSpeaking = false;
      });
 
      this.audioTrackDuration = await this._player.getAudioTrackDuration();
      // start audio duration tracking
      this._startDurationTracking(this.audioTrackDurationvolume);
    } catch (e) {
      console.error("AudioAndSpeak -> playSound"e);
      firebase.crashlytics.sendCrashLog('AudioAndSpeak -> playSound :' + e);
    }
  }
  private async _startDurationTracking(durationvolume) {
    if (this._player && this._player.isAudioPlaying()) {
      this._player.volume = volume;
      const timerId = timer.setInterval(() => {
        this.remainingDuration = duration - this._player.currentTime;
      }, 500);
    }
  }
}


You need yo add the service on the contractor

import { AudioAndSpeak } from "../../shared/AudioAndSpeak";

 constructor(
    ...
    private audioAndSpeakAudioAndSpeak,
    ...
  ) {...}

to call audio file

 this.audioAndSpeak.playSound(audioFilePath);

to call speak

this.audioAndSpeak.speak'TEXT' , "en-GB" );

Thanks,
Roi Kolbinger

28 June 2020

Game built in Angular and Typescript- for Android users with NativeScript

During the corona virus vacation, I took the time to learn something new- NetiveScript.
I took a course - at one of the best in the market - Maximilian Schwarzmüller.

https://pro.academind.com/p/nativescript-angular-build-native-ios-android-web-apps

I built a game for my girls.

For Hebrew speakers
Ages 2-4 they will learn Colors, Shapes and Animals.
Ages  4-6 who will teach Numbers and Letters
Ages  6-9 who will teach addition and multiplication .. and learning English in stages ... Letters Numbers, Colors, Shapes and Animals.
For English speakers, the same thing only in English.

Now because everything is object-based .. I tried another language - Spanish .. In the meantime, there are only Numbers and Animals.


The game itself is written in angular and typescript.
It has 3 main components.
Component for choosing a language, Component for chose a game and of course Component of the game itself..

NativeScript gives me, as a web developer, the ability to build an app for both Android and iOS

The game is now in Google play - and Called - My First Game

https://play.google.com/store/apps/details?id=org.nativescript.roifirstgame

Over time, I'll post my insights from NativeScript

Install ... Let the kids play and I'd love to get feedbacks ...
Roi


26 June 2020

SharePoint Service Provisioning - the service stuck on starting

When I tried to run SharePoint service - Manage Metadata Web Service on the Central Admin ... I wait and still Staring (Stuck)...


So again I ran the command (From SharePoint PowerShell)


Get-SPServiceInstance -Server SERVERNAME| where-object  {$_.TypeName -eq "Managed Metadata Web Service"} | Start-SPServiceInstance -confirm:$false > $null

And I got the Error


Start-SPServiceInstance : An object of the type Microsoft.SharePoint.Administration.SPServiceInstanceJobDefinition named "job-service-instance-ba7339e3-fb42-49c4-ac66-ab08e84eae0f" already exists under the parent Microsoft.SharePoint.Administration.SPTimerService named "SPTimerV4".  Rename your object or delete the existing object. At line:1 char:111 + ... eb Service"} | Start-SPServiceInstance -confirm:$false > $null +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : InvalidData: (Microsoft.Share...ServiceInstance:    SPCmdletStartServiceInstance) [Start-SPServiceInstance], SPDuplicateObject   Exception     + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletStartSer    viceInstance

I deleted the job

$jobToDelete = Get-SPTimerJob | ? { $_.name -eq "job-service-instance-ba7339e3-fb42-49c4-ac66-ab08e84eae0f" }
 $jobToDelete.Delete()


You tried to stop again

Stop-SPServiceInstance -Identity ba7339e3-fb42-49c4-ac66-ab08e84eae0f

But I also got the job stuck - Deleting it again 

$jobToDelete = Get-SPTimerJob | ? { $_.name -eq "job-service-instance-ba7339e3-fb42-49c4-ac66-ab08e84eae0f" }
$jobToDelete.Delete()

I stopped timerJob on the server 

Then I tried a different way


$service = Get-SPServiceInstance -Identity ba7339e3-fb42-49c4-ac66-ab08e84eae0f


$service.unprovision()
$service.update()
iisreset /noforce




I was waiting to see that he was really disabled


$service.provision()
$service.update()
iisreset /noforce


I turned on the TimerJob

And It works :)