Let NAV Speak! (with .NET Interop and NAV 2009 R2)

Let NAV Speak! (with .NET Interop and NAV 2009 R2)

  • Comments 8

In this blog is described a very simple usage of the .NET interoperability feature with Microsoft Dynamics NAV 2009 R2 and can be considered an extension of my previous blog: http://blogs.msdn.com/b/nav/archive/2010/07/09/let-nav-speak-with-a-simple-and-useful-client-add-in.aspx.

It is intended just to familiarize you with this brand new feature proposed with the NAV 2009 R2 release.

If you want to know more about .NET interoperability for NAV 2009 R2, please refer to MSDN link:

Extending Microsoft Dynamics NAV Using Microsoft .NET Framework Interoperability

http://msdn.microsoft.com/en-us/library/gg502499.aspx

The .NET interoperability code snippet in this blog is based on the System.Speech namespace.

http://msdn.microsoft.com/en-us/library/ms554861(v=VS.90).aspx

My ingredients:

  • NAV 2009 R2
  • Windows 7 Enterprise

Create your "Speak it!" action and let NAV speak Customer Names :

1. Open Classic Client

2. Go to the Object Designer

3. Select Page object (alt+g)

4. Select Page 22 "Customer List"

5. Design Page 22 "Customer List" (alt+d)

6. Select View > Page Actions (al+v, o)

7. Create a new Action (F3) in the ActionItems container (see below)

8. Change the properties of the Action as below:

Caption - Speak it !

Image - ViewComments

Promoted - Yes

PromotedCategory - Process

PromotedIsBig - Yes

9. Edit the code in the Speak it! Action (F9)

10. Add those LOCAL variables

dnSpeech

DataType: DotNet

Subtype: System.Speech, Version=3.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35.System.Speech.Synthesis.SpeechSynthesizer

RUNONCLIENT: Yes
Synth

DataType: DotNet

Subtype: System.Speech, Version=3.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35.System.Speech.Synthesis.SpeechSynthesizer

RUNONCLIENT: Yes

dnVoiceGender

DataType: DotNet

Subtype: System.Speech, Version=3.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35.System.Speech.Synthesis.VoiceGender

RUNONCLIENT: Yes

I

DataType: Integer

 

NOTE: RUNONCLIENT is a property of each DotNet variable (shift+f4)

11. Add this code snippet in the OnAction trigger

...

// Copyright © Microsoft Corporation. All Rights Reserved.

// This code released under the terms of the

// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

// Use the constructor to create a new Synthesizer

Synth := dnSpeech.SpeechSynthesizer();

// http://msdn.microsoft.com/en-us/library/system.speech.synthesis.voicegender(VS.90).aspx

// This is an enumeration assignment:

// 0=NotSet,1=Male,2=Female,3=Netural

dnVoiceGender := 2; //Female

// NOTE: it will take the voice depending on what is

//  installed locally (e.g. Windows 7 has Microsoft Anne voice)

Synth.SelectVoiceByHints(dnVoiceGender);

// Please, speak slowly (range [-10:10])

Synth.Rate := -3;

Synth.SetOutputToDefaultAudioDevice();

Synth.Speak(FORMAT(Name));

// Row below is not needed. Synth is a local variable therefore it will be

// automatically disposed

// Synth.Dispose;

...

12. Save and compile (ctrl+s) page 22 "Customer List"

Now... you are ready to let NAV speech the Customer Name from the customer list by simply click on the "Speak it!" action.

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 4 and 4 and type the answer here:
  • Post
  • I don't know how useful this example would be considering dotNET objects are instantiated at the server so the user would not be able to hear anything.

  • I dare to say that this is not correct, Rashed.

    If you read the blog, you have to set the DotNet variable property RUNONCLIENT to TRUE. In this way, the .NET assembly used is created at client (RTC) side. If you do not hear anything this may be due to the fact that you have not set correctly this property or your outputdevice goes nowhere. You can just try to add this code

    Synth.SetOutputToWaveFile('C:\Temp\test.wav');

    and comment

    //Synth.SetOutputToDefaultAudioDevice();

    Hope this helps, in your case.

    P.S. I have tested this simple code snippet in a 3tier shared HW, 3 tier non-shared hw, standalone and it works like a charm.

  • Hi Duilio,

    I have the following questions:

    1. How to get the Public Key Token as per your code snippet "Culture=neutral,PublicKeyToken=31bf3856ad364e35.System.Speech.Synthesis.SpeechSynthesizer"? This example is different from your previous blog (Jul 2010) where we need to use "sn" command to generate the PKT (Public Key Token)? Is this example also using the custom add-ins "NSpeech" from your previous blog? I understand that our own machine may generate unique PKT.

    2. If I did not define the "RunObject" property of the Action that we need to create above along with other properties such as "Promoted", "PromotedCategory" and "PromotedIsBig" - my new action "Speak It" will not be shown when I test/launch the page. Only when I create a dummy page "Speak It" and put this so called "dummy page" as the page name on "RunObject" property, the page can display the new action above. Is it a bug in NAV 2009 R2?

    Appreciate if you could help.

  • I have the following questions:

    1. No need of PKT. Forget it if you want to use .NET interop. I guess you only need to read the blog and read the documentation contained here to understand the basics of .NET interop

    msdn.microsoft.com/.../gg502499.aspx

    2. You need to familiarize with RTC too. Please refers to MSDN. No bug at all.

    Follow the instructions in this blog and play with those. I am sure you will succeed in your design.

  • 1. No need of PKT. Forget it if you want to use .NET interop. I guess you only need to read the blog and read the documentation contained here to understand the basics of .NET interop

    msdn.microsoft.com/.../gg502499.aspx

    2. You need to familiarize with RTC too. Please refers to MSDN. No bug at all.

    Follow the instructions in this blog and play with those. I am sure you will succeed in your design.

  • Hi Duilio.

    Any idea how to handle the security message for using an external component automatically?

    Best regards,

    Patrick

  • This is a very tricky question and development team has long looked at how to implement and manage security and trustability between components. This may also be the subject of future changes / enhancement.

    Using the property RunOnClient for DotNet datatypes may results in pop up confirmation dialog which not allows to “permit always” but only “allow this time” or “disallow this time and ask next time".

    This is and intended feature security related.

    It has been noticed, however, that setting ServicePrincipalNameRequired=True in the RTC ClientUserSettings.config allows RunOnClient=Yes without questioning the user about security. Can you try that ?

  • This should also have been depicted here if I am not wrong

    (you can traslate it using www.microsofttranslator.com/Default.aspx )

    www.comporsys.de/.../der-nav-client-versucht-eine-externe-komponente-auszufuehren

Page 1 of 1 (8 items)