Skip to main content

Notifications

Dynamics 365 Community / Blogs / Jesús Almaraz blog / Text to Speech in Navision ...

Text to Speech in Navision Business Central.

Introduction

Voice is a very interesting interface between machines and humans. In this post we show how to convert text to speech. The interesting stuff for us is that the source of the text is NAV/BC365 information.

How-to: Control Add-in

I think the is a lot of ways to do this but the easier and logic is to make an add-in Control. To get this goal we use SpeechSynthesis component, supported by Edge, Mozilla and Chrome: https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis . I use it in a very basic way, but you can set the volume, speed and the voice of the audio. Fun fact: Edge talk with masculine voice and Chrome with female voice.
We create first file a JavaScript with only three lines (This post eased a lot the making https://code.tutsplus.com/es/tutorials/let-me-hear-your-browser-talk-using-the-speech-synthesis-api--cms-24971 ):
function TextToSpeech(InputText)
{
    var utterance  = new SpeechSynthesisUtterance();
    utterance.text = InputText;
    speechSynthesis.speak(utterance);
}
And the NAV Add-in file declaration:
controladdin TextToSpeech
{
    Scripts = 'TextToSpeech.js';
    procedure TextToSpeech(InputTextText)
}
Done. Let´s see an example.

NAV Example: Tell me the instructions!!

In the example we make a page extension to Assembly Order with a new control. When we click or touch this control (Tell me the instructions control in screen), NAV read the Assembly Order comments and send them to the computer audio:
TextToSpeech.png
Page extension:
pageextension 69000 "Voice Assembly Order" extends "Assembly Order"
{
    layout
    {
        addlast(Control2)
        {
            field(CommentSpeech'Tell me the instructions!!')
            {
                trigger OnDrillDown()
                begin
                    InstructionsSpeech();
                end;
            }
            usercontrol(TextToSpeechTextToSpeech)
            {
                ApplicationArea = All;
                Visible = true;
            }
We include here  a new text control and a declaration of the previous Add-in. When control CommentSpeech is pushed we call the function InstructionsSpeech:
    procedure InstructionsSpeech()
    var
        AssemblyCommentRecord "Assembly Comment Line";
    begin
        Assemblycomment.SetRange("Document Type", "Document Type");
        AssemblyComment.SetRange("Document No.", "No.");
        if not AssemblyComment.FindSet() then
            exit;
        repeat
            CurrPage.TextToSpeech.TextToSpeech(AssemblyComment.Comment);
        until AssemblyComment.next = 0;
    end;

Asynchronous

Called my attention that the add-in runs in asynchronous way, so you can edit the card and keep on working with NAV at the same time you listen to the comments.

Comments

*This post is locked for comments