Community Blog Buy Now

Misty Community Forum

How do I convert javascript audio localization to C#?

How do I convert the javascript localization code to C#? Below is my first attempt:

Javascript code:

function registeraudiolocalisation()
      misty.set("speechsourceangle", 0.0, false);
      misty.addreturnproperty("sound", "degreeofarrivalspeech");
      misty.registerevent("sound", "sourcetrackdatamessage", 10, true);

C# Code:

private void registerAudioLocalization()
     _speechSourceAngle = 0.0;

     IList<NativeValidation> listNVal = new List<NativeValidation>();
     NativeValidation nval = new NativeValidation();
     nval.Name =  "DegreeOfArrivalSpeech";
     nval.Comparison = ComparisonOperator.Equal;
     nval.Value = true; // "sound";
    _misty.RegisterEvent(EventType.SourceTrackDataMessage, 10, true, listNVal, null, SoundCallBack);

Hey @wspeerbrecker, I’ll take a look at this today and see if I can share an example.

In the meantime I’ve moved your post into the Misty Development category where it will be more visible to the rest of the community, in case another community member has sample code they can share :slight_smile:

Hey @johnathan - that would be great to have a C# example of audio localization. I am trying to convert the JavaScript Misty-Concierge-Template to C# but it is taking a lot of time on audio localization and look to face logic. So any C# examples will be very useful. Thanks.

Hey, @wspeerbrecker!

I’m able to see the degree of arrival speech by using the following. This is pretty simplistic, and you’ll likely want to modify it for your own use – apply at your own risk :wink:

In the OnStart method, we register for SourceTrackDataEvent messages and attach a callback to SourceTrackDataMessageEventReceived events. Then we record audio for 10 seconds.

		public void OnStart(object sender, IDictionary<string, object> parameters)
			_misty.ChangeLED(255, 36, 0, OnResponse);
            Debug.WriteLine("Debuggin your skill...");
            _misty.RegisterSourceTrackDataEvent(100, true, null, null);
            _misty.SourceTrackDataMessageEventReceived += ProcessSourceTrackDataMessageEvent;
            _misty.StartRecordingAudio("AudioLocalization", null);

Then, in a “User Callback Functions” region, we define the ProcessSourceTrackDataMessageEvent callback. Here I just print the value for DegreeOfArrivalSpeech to the debug console:

        #region User Created Callback Functions
        private void ProcessSourceTrackDataMessageEvent(object sender, ISourceTrackDataMessageEvent sourceTrackDataMessageEvent)

Great - I will try it - thanks.