Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
MIT License
2.8k stars 1.83k forks source link

Exception (SPXERR_MIC_NOT_AVAILABLE) #436

Closed rambabuk1222 closed 4 years ago

rambabuk1222 commented 4 years ago

Describe the bug I have implemented same code in my bot framework (c#) project

To Reproduce Steps to reproduce the behavior:

                        var config = SpeechConfig.FromSubscription("*************", "westus");
                        using (var recognizer = new SpeechRecognizer(config, AudioConfig.FromDefaultMicrophoneInput()))
                        {

                            await recognizer.StartCont

Bot Error inuousRecognitionAsync();

                        }

Expected behavior When I speak app should be take voice and convert into text and send to bot.

Version of the Cognitive Services Speech SDK 3.0

Platform, Operating System, and Programming Language

Additional context

drparam commented 4 years ago

I have the same exact issue and appreciate if anyone in BOT team can provide solution for above speech to text. This works fine in emulator when the Visual studio project is run but not after deploying. So connecting the emulator to azure web bot app is throwing same error message (SPXERR_MIC_NOT_AVAILABLE). Appreciate if this can be resolved at the earliest.

chrisbasoglu commented 4 years ago

@rambabuk1222 we need some more details. For example you say the OS is azure. What does that mean? You say the programming language is C#, but the Browser is chrome and MS Teams, how are you running your C# program within Chrome or MS Teams?

@drparam where are deploying to?

jhakulin commented 4 years ago

Mic related problem are most often related to your specific HW configuration and not the problem in Speech SDK. Please ensure microphone is working OK in your machine, ideally if you are able to verify that your audio drivers support 16bit 16kHz PCM audio capture that would be the same as Speech SDK is using.

BrianMouncer commented 4 years ago

I usually see SPXERR_MIC_NOT_AVAILABLE if using the from microphone APIs on a device with no input device. That or from a UWP app that hasn’t requested and accepted the microphone capability.

If you’re using the emulator or using remote desktop, you will need to modify your connection settings so that you redirect audio (by default Terminal Services only redirects speakers, you need to also redirect the microphone).

If you actually want to use the app on a device with no microphone, then switch to using the from file or stream input methods. Here is one example, https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/csharp/dotnet/from-file

rambabuk1222 commented 4 years ago

Thanks for you response. I'm using speech SDK for Microsoft bot framework project. When I run the app in enumerator it works fine.After hosting it into azure, It is not working as I expected. please find complete c# code below. I tested my microphone with similar online app and its working fine.


using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;

namespace Microsoft.BotBuilderSamples.Bots
{
    public class EchoBot : ActivityHandler
    {
        protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            await turnContext.SendActivityAsync(MessageFactory.Text($"Echo: {turnContext.Activity.Text}"), cancellationToken);
            var config = SpeechConfig.FromSubscription("----------------------------", "northeurope");
            using (var recognizer = new SpeechRecognizer(config, AudioConfig.FromDefaultMicrophoneInput()))
            {
                await turnContext.SendActivityAsync(MessageFactory.Text($"Echo: Please some words."), cancellationToken);
                var result=  await recognizer.RecognizeOnceAsync();

                await turnContext.SendActivityAsync(MessageFactory.Text($"Echo: {result.Text}"), cancellationToken);
            }
        }

        protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
        {
            foreach (var member in membersAdded)
            {
                if (member.Id != turnContext.Activity.Recipient.Id)
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text($"Hello and welcome!"), cancellationToken);
                }
            }
        }
    }
}
chrisbasoglu commented 4 years ago

^^ After hosting it into azure, It is not working as I expected Azure VMs don;t have microphones. Can you be more detailed about your scenario?

drparam commented 4 years ago

Hi Chris

Thanks for getting back. I think we need to understand the scenario here to be precise in finding answer. Can I setup a call so we can do a screensharing session to solve this issue, please?

If you can share your email, I will then send an invite based on your availability.

Regards

Dr. Subramani Paramasivam (MANI)

From: Chris Basoglu notifications@github.com Sent: 25 November 2019 00:21 To: Azure-Samples/cognitive-services-speech-sdk cognitive-services-speech-sdk@noreply.github.com Cc: Subramani Paramasivam Mani@dageop.com; Mention mention@noreply.github.com Subject: Re: [Azure-Samples/cognitive-services-speech-sdk] Exception (SPXERR_MIC_NOT_AVAILABLE) (#436)

^^ After hosting it into azure, It is not working as I expected Azure VMs don;t have microphones. Can you be more detailed about your scenario?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/436?email_source=notifications&email_token=AMYZZYUPQDIJKQ2ZZFODPXTQVMK6VA5CNFSM4JOGJ43KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFAZDFY#issuecomment-557945239, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMYZZYV2KVKN4SLNOOWNJLLQVMK6VANCNFSM4JOGJ43A.

drparam commented 4 years ago

Hi Chris

I have recorded the issue with speech to text and the quick 2 minutes video is available for you herehttps://1drv.ms/u/s!AnTZZKrEsfCHg5BaVG5kssU3u_ULgQ?e=CPG4OT. The source code is available in this githubhttps://github.com/rambabuk1222/EchoBot for you to test the same.

Appreciate a quick turn around on this as we have been waiting to find a solution for a long time.

Regards

Dr. Subramani Paramasivam (MANI)

jhakulin commented 4 years ago

Thanks a lot for all the details and test code, we will try that and let you know.

jhakulin commented 4 years ago

@drparam Please check the following tutorial on how to create voice enabled bot using speech SDK.

https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/tutorial-voice-enable-your-bot-speech-sdk

drparam commented 4 years ago

Thanks for getting back. I have tried this and as it was not working, I have reached out with recorded video and full github code in my previous response. I have been chasing with this work for more than a month speaking to various Microsoft AI team members and as per their last suggestion tried to reach via Github. I am afraid that we are going in circles but not reaching a working solution. Before deployment it works fine in my local emulator, but not after deploying. I really appreciate if you can see the demo video and the code provided and advise on a working solution. NOTE: The provided Github solution is a simple solution a copy of Microsoft Github sample and based on the suggested documents.

jhakulin commented 4 years ago

Thanks for more information, it is not certainly good if even the tutorial I linked did not help you get further. I will discuss with the engineers working on creating voice enabled bots and we'll try to get more information about the issue.

Regarding your sample and video, I did look those, but personally I do not know (yet) what microphone the bot sample actually tries to use when bot is deployed to Azure Portal. When running Bot sample locally, it uses your machine's microphone which works.

gghizila commented 4 years ago

I had to delete a couple of my answers as I kept getting it wrong and I was not sure what is the scenario. Still not sure but after chatting with members or our team we know what is not working and can't work.

I am simply reiterating some of the statements from Chris and Jarno but the bot code is running on the service there is no way that running in the service gives access to the microphone on the client machine (nor on the service machine but that does not matter much). Running it locally it does access the microphone on your machine but there is no component on the service where you can simply open the microphone and expect to be redirected to the client.

What we offer right now is the ability to connect your bot to a channel that allows you to stream audio to it not just plain activities, the link previously sharedTutorial: Voice-enable your bot using the Speech SDK should give you the information you need to get this going.

Note that this approach will not require to use the speech SDK in the bot but in the client application. Also emulator will not provide you with the audio from client yet you can use this sample aplication to connect to your bot with voice: Direct Line Speech Client. Hope this helps.

If you have trouble handling any of the steps in the tutorial, please let us know.

bos-sudhakar commented 4 years ago

Will this work on web or only console application? if yes how?

gghizila commented 4 years ago

The Speech SDK has C#, Java, Xamarin and quite a few other projections so one can develop apps on Windows, Android, iOS or middle tier web services, console apps are just the simplest to understand the entire flow. Of course the microphone is not available in web services directly if the SDK is used in the service, one will have to stream the audio and use stream based APIs instead of microphone, there are a number of samples for that use of the APIs. For a browser there is the javascript SDK that can handle that.

jhakulin commented 4 years ago

Closing this as the issue is known and solution proposed. Let us know if there is more information needed.

karthikcs commented 3 years ago

Hi, I am getting this error while I am trying to use Microphone different from default mic. I think I am not providing proper DEVICE_ID. I am writing my client in python on Windows 10 local machine. Here is my code snippet (Modified from Azure Example). Can you please through light on how to get proper DEVICE_ID of a mic on Windows 10

def translation_once_from_mic(src_lang, dest_lang, outfile):
    """performs one-shot speech translation from input from an audio file"""
    # <TranslationOnceWithMic>
    # set up translation parameters: source language and target languages
    print(src_lang, dest_lang)
    translation_config = speechsdk.translation.SpeechTranslationConfig(
        subscription=speech_key, region=service_region,
        speech_recognition_language=str(src_lang),
        target_languages=([str(dest_lang)]))
    # audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
    audio_config = speechsdk.audio.AudioConfig(device_name="MMDEVAPI\AudioEndpoints")
karthikcs commented 3 years ago

Friends, I figured it out.. I was reading Microsoft Docs here. I understood the format of the device ID will be as {0.0.1.00000000}.{5f23ab69-6181-4f4a-81a4-45414013aac8}

When I was going through all the properties of the device driver in Control panel, I found the property called Device Instance Path. If you leave the initial part which is the path like SWD\MMDEVAPI\{0.0.1.00000000}.{8c85a4e8-3a66-4857-8883-96d100179b47}. The last part of this value is the Device ID. Hope this helps..

samkuls commented 3 years ago

Getting exception when deploy Speech SDK on Azure webapp SPXERR_MIC_NOT_AVAILABLE

Describe the bug When I am trying to deplpy my Speech SDK (from Microphone To Speech)on Azure webapp getting SPXERR_MIC_NOT_AVAILABLE though it is working locally and over local iis deployed also.

To Reproduce Steps to reproduce the behavior: Write below method on .net core api and deploy on Azure

public async Task<IActionResult> MicrophoneToSpeechAsync(string languageIso6391Code)
{
    var subscription = _config.GetValue<string>("SubscriptionId");
    var location = _config.GetValue<string>("Region");
    var config = SpeechConfig.FromSubscription(subscription, location);
    config.SpeechRecognitionLanguage = string.IsNullOrWhiteSpace(languageIso6391Code) ? "en-us" : 
    languageIso6391Code;

    // Creates a speech recognizer.
    using (var recognizer = new SpeechRecognizer(config))
    {
        Console.WriteLine("Say something...");
        var result = await recognizer.RecognizeOnceAsync();
        List<SpeechCommonService.DetectedLanguage> language = null;
        // Checks result.
        if (result.Reason == ResultReason.RecognizedSpeech)
        {
            Console.WriteLine($"We recognized: {result.Text}");

        }
    }

} Extected behaviour it should understand the spoken words over microphone and convert it to text.

rhurey commented 3 years ago

It may be better to open this as a new issue.

Can you help clarify your intentions? When running in a webapp, the code will be executed in the cloud, where there isn't a microphone. If you want to recognize speech from a web page, the JavaScript version of the Speech SDK can do that.

samkuls commented 3 years ago

@rhurey : my intention is to create one api which can be consumed by my organization to perform STT through microphone. i need solution in .Net. Thanks in advance.

samkuls commented 3 years ago

@gghizila : I am using Speech SDK in Service API. How to use stream based APIs instead of microphone in c#?? Thanks.