Let NAV Speak (with a Simple and Useful Client Add-in)

Let NAV Speak (with a Simple and Useful Client Add-in)

Rate This
  • Comments 8

In this blog you will find the source code (below) to “let NAV speak.” You would have a wide range of possibilities to use this simple Add-in and enlarge this project.

If you want to know more about Client Add-ins you can refer to this MSDN link:

Extending the RoleTailored Client Using Control Add-ins and Microsoft Dynamics NAV 2009 SP1

This simple Client Add-In is based on System.Speech namespace:

Microsoft.Speech.Synthesis Namespace

Step by step creation of the NSpeech Add-In

(Remember the ‘DodgeBall’ rules: Develop, Sign, Place, Register and Develop)

  1. DEVELOP your add-in (in Visual Studio)
  2. Strong SIGN and build
  3. PLACE DLLs into Add-ins folder
  4. REGISTER the add-in in Table 2000000069, Client Add-in
  5. DEVELOP your C/AL code (in Object Designer)

A. Create a New Class Project

  1. Open Visual Studio (in this example I am using Visual Studio 2010)
  2. Create a New Project (CTRL+SHIFT+N) with these parameters
    • Visual C# – Windows
    • Class library
    • .NET Framework 3.5
    • Name: NSpeech
    • Location: C:\TMP (or whatever location you like)
    • Solution Name: NSpeech
    • Create directory for solution

NSpeechVS

B. Create a Strong Name Key (SNK)

  1. Go to Project > Properties (NSpeech Properties…)
  2. From the Project Properties form go to the Signing tab
  3. Tick the Sign the assembly option
  4. Create a New SNK (e.g. TestSpeechNav.snk)

NSpeechSign

C. Add References to the Project

  1. Click on the Class1.cs tab (return to the project)
  2. In the Solution Explorer window select Reference, right Click, Add Reference
  3. Add reference to
    • Microsoft.Dynamics.Framework.UI.Extensibility (Version 1.3.0.0) (By default, the path to the assembly is C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client)
    • System.Drawing (Version 2.0.0.0)
    • System.Speech (Version 3.0.0.0)
    • System.Windows.Forms (Version 2.0.0.0)

NSpeechRef

D. Develop your NSpeech Project

(You can simply copy and paste this code into your Class project.)

using System;

using System.Collections.Generic;

using System.Text;

using System.ComponentModel;

//Add a reference to the Add-in API (see the solution explorer) and all relevant references

//Use all relevant references

using System.Drawing;

using System.Windows.Forms;

using Microsoft.Dynamics.Framework.UI.Extensibility;

using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;

//this is to let this add-in speech

//http://msdn.microsoft.com/en-us/library/dd146744(v=office.13).aspx

using System.Speech;

using System.Speech.Synthesis;

namespace NSpeech

{

    //Develop the control add-in class.

    //Assign a name to the control add-in (MyCompany.MyProduct.MyAddIn)

    [ControlAddInExport("Cronus.DynamicsNAV.NSpeech")]

    [Description("Let this Add-in Speak")]

  

    //Select a base class as a starting point.

    //Select interfaces to implement features, such as data binding or event handling.

    public class Class1 : StringControlAddInBase

    {

        //Implement control creation

        protected override Control CreateControl()

        {

            //Create a brand new TextBox

            TextBox control = new TextBox();

           

            //Define TextBox size

            control.MinimumSize = new Size(50, 0);

            control.MaximumSize = new Size(500, Int32.MaxValue);

           

            //Add a DoubleClick event for the TextBox

            control.DoubleClick += new EventHandler(control_DoubleClick);

            return control;

        }

        //Define a voice synth

        private SpeechSynthesizer synth;

        private void control_DoubleClick(object sender, EventArgs e)

        {

            //create a new speech synth and set default audio device

            synth = new SpeechSynthesizer();

            synth.SetOutputToDefaultAudioDevice();

           

            //Pass TextBox content in a string variable

            string data = this.Control.Text;

          

            //... and let NAV speak it!

            synth.SpeakAsync(data);

        }

    }

}

E. Build the NSpeech.dll

  1. Once you have all setup, you are ready to build your Client Add-In. Go to Build > Build NSpeech

F. Place DLL into Add-in folder

  1. Locate/copy/paste NSpeech.dll (should be in your C:\TMP\NSpeech\NSpeech\bin\Debug folder) to the Add-ins folder of a machine where the RoleTailored client has been installed

(typically the Add-ins folder is here: C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client\Add-ins)

G. Determine the PKT (Public Key Token) of NSpeech

  1. Launch the Visual Studio Command Prompt
  2. In the VSCP:

Sn –T “C:\TMP\NSpeech\NSpeech\bin\Debug\NSpeech.dll”

In the following example, 250f71f35a467631 is the PKT (Public Key Token) needed to register the Add-in into NAV. (You will have another value.)

NSpeechSn

H. Register the NSpeech dll

  1. Open Classic Client
  2. Open Object Designer (SHIFT+F12)
  3. Select Table object (ALT+B)
  4. Run Table 2000000069 Client Add-in
  5. Insert a new line with these values:
Field Value
Control Add-in Name Cronus.DynamicsNAV.NSpeech
Public Key Token 250f71f35a467631 (this is an example)
Version 1.0.0.0
Description Let this Add-in Speak

How to Use This Add-in

As an example, you can just let NAV speak the content of the field “Name” in Customer Card page (Page 21).

  1. Open Classic Client
  2. Go to Object Designer (SHIFT+F12)
  3. Select Page object (ALT+G)
  4. Design Page 21 Customer Card
  5. Go to Name Field and Edit properties (SHIFT+F4)
  6. Fill the ControlAddIn property with this value Cronus.DynamicsNAV.NSpeech;PublicKeyToken=250f71f35a467631 (change the PublickKeyToken value to the one that you have determined at step G.)
  7. Save and compile the page (CTRL+S)

Now…you are ready to let NAV speak the Customer Name from the customer card by simply double clicking on on the Name!

This simple Client Add-in project may be used in, e.g.

  • Speak an alert if the availability of an Item is lower than expected in a document page (e.g. sales quote)
  • Speak an alert if a Customer exceeds assigned Credit Limit
  • Speak internal comments for an item, a vendor, a customer, wherever this is needed
  • … and many more

This simple Client Add-in project may be enlarged, e.g.

  • It could be possible to set the volume of the voice
  • It could be possible to set the rate of the voice
  • It could be possible to select another voice instead of “Microsoft Anne” default in order to speak words with proper accent language
  • It could be possible to save a .wav file instead of speaking it or even perform both activities
  • … and many more

These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.

Best Regards,

Duilio Tacconi (dtacconi)

Microsoft Dynamics Italy

Microsoft Customer Service and Support (CSS) EMEA

Leave a Comment
  • Please add 6 and 7 and type the answer here:
  • Post
  • Amazing add-in! :D I saw last week in Madrid and I just install on my computer. Thank you very much

  • Great post Duilio!

    I tested it with an italian version of Nav2009sp1 and it works fine.

    I hope Miscosoft people will publish other example about add-in capabilities like this.

  • Hi Duilio! That's fine!

    This example helped me in discovering new opportunities with wonderful NAV!

  • Dear Duilio,

    I am interested to try and test this and have read your latest blog that you published a few days ago on "Let NAV Speak"(31 Dec 2010). However, is it possible to get the control add-in object (NSpeech) from you? Or is there any way for me to download this? Thanks if you could help.

  • Hi Danny, this Client Add-in is quite simple. Just read the step by step construction and you surely will succeed in develop it your own. From this blog you can then familiarize with the Add-In development. I may suggest you to check

    msdn.microsoft.com/.../dd983700.aspx

    and Cabell blog too

    blogs.msdn.com/.../cabeln

    Unfortunately, I am not allowed to attach / redispatch dll files for our internal policy. Also FOB files shouldn't be allowed to be posted from us that is why you find txt object only.

    As mentioned, follow the simple example. Is pretty much easy.

  • Dear Duilio,

    Thank you veru much for your prompt reply. If it is the policy to not allow to attach any DLL or FOB files, I will respect that. Thanks again for your help.

  • Hi DuilioTacconi..

                       Thanks for your information..

  • i tested it but i have error when running the page.

Page 1 of 1 (8 items)