Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add microphone helper sample #1326

Merged
merged 4 commits into from Nov 21, 2017
Merged

Add microphone helper sample #1326

merged 4 commits into from Nov 21, 2017

Conversation

minkom-ms
Copy link

Microphone helper sample to query microphone presence and availability at runtime. Partners have asked for such sample to make decisions in game whether to show speech use helpers.

@msftclas
Copy link

msftclas commented Nov 9, 2017

CLA assistant check
All CLA requirements met.


class MicrophoneHelper
{
#if ENABLE_WINMD_SUPPORT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a note that this only works for IL2CPP and .NET 4.6.

We also need to add the dll references for this to work properly in the MRTK project. We will also need to add documentation for devs to know they will also need to setup their projects to use this as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works with both .Net and IL2CPP backends. There is no need for extra dll references. There shouldn't be any need to do extra setup in your project to use this. If you know of a scenario that adding this script will break let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. I was just going off the Unity Documentation regarding this usage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment to the class and a link to the Unity documentation.

#endif

// TODO: namespace might need to be updated for consistency with other MRTK samples
namespace MixedRealityToolkit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace HoloToolkit.Unity

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

}
}

public class MicrophoneHelperSample : MonoBehaviour
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classes should be in their own files.

Also this class is in the generic namespace instead of the MRTK's

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

#if ENABLE_WINMD_SUPPORT
async void Update ()
#else
void Update()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: private access modifier

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

// This sample code is a modified version of an official UWP sample which can be found on:
// https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/SpeechRecognitionAndSynthesis/cs/AudioCapturePermissions.cs
//
//*********************************************************
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the other headers in the toolkit.

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

/// For full details see unity documentation page
/// https://docs.unity3d.com/Manual/IL2CPP-WindowsRuntimeSupport.html
/// </summary>
class MicrophoneHelper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing access modifier


namespace HoloToolkit.Unity
{
enum MicrophoneStatus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing access modifier

{
#if ENABLE_WINMD_SUPPORT
// If no recording device is attached, attempting to get access to audio capture devices will throw
// a System.Exception object, with HResult = ‭0xC00DABE0‬ set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: <summary> tags?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean here. Can you elaborate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the comment to use <summary> tags.

or even <remarks> tags explaining it's usage.

public class MicrophoneHelperSample : MonoBehaviour
{
[Tooltip("Assign key to quickly test the microphone helper code")]
public KeyCode checkMicrophoneKey = KeyCode.M;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we checked to make sure KeyCode.M isn't used elsewhere in the project?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A search in all .cs files did not return any other references.

#if ENABLE_WINMD_SUPPORT
var status = await MixedRealityToolkit.MicrophoneHelper.GetMicrophoneStatus();
var status = await MicrophoneHelper.GetMicrophoneStatus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can use MicrophoneHelper.GetMicrophoneStatus() without having to check for ENABLE_WINMD_SUPPORT in our implementation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also make the stub method async, but then I'll get a warning that await is not being used anywhere. If you're fine with an extra warning I can change that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will the warning show? During compile or build time?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If compile time, I'd rather not, but if it's at build time, then it's not that big a deal.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is not a good idea. async/await were introduces with C# 5 and require .Net 4.5+. It would be better it remained this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to think about ways to make this simpler for devs to use in their own code.

}
catch (Exception exception)
{
// This can be replicated by using remote desktop to a system, but not redirecting the microphone input.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed Reality won't work in remote desktop or VM contexts, so you can probably edit down this comment a little to avoid confusion (still possible to disable all of the audio endpoints though)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, would this also include Unity's holographic remoting?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holographic remoting is still playing in the editor, where this script would be no-op. I will remove the remote desktop references from the comments.

@keveleigh keveleigh changed the base branch from master to Dev_Working_Branch November 21, 2017 21:15
@keveleigh keveleigh merged commit e1efe5f into microsoft:Dev_Working_Branch Nov 21, 2017
@minkom-ms minkom-ms deleted the user/minkom-ms/microphone-helper-sample branch November 21, 2017 21:16

namespace HoloToolkit.Unity
{
public class MicrophoneHelperSample : MonoBehaviour
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a test/example class? It doesn't belong in the core toolkit folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants