I pulled down this repo and built it in Android Studio
When I hit the recognize button I get this error:
"Recognition failed with Canceled. Did you enter your subscription?
WebSocket Upgrade failed with an authentication error (401). Please check the subscription key or the authorization token, and the region name."
I was able to verify my subscription key as valid by using powershell to test a post (see below)
$FetchTokenHeader = @{
'Content-type'='application/x-www-form-urlencoded'
'Content-Length'= '0'
'Ocp-Apim-Subscription-Key' = 'my key here'
}
$OAuthToken = Invoke-RestMethod -Method POST -Uri https://api.cognitive.microsoft.com/sts/v1.0/issueToken -Headers $FetchTokenHeader
$OAuthToken
The test was successful and I got an auth token. So I know that is correct.
But I could not find what region my resource was in, It just said global.
I tried every one of regions, including the global listed in the azure website to no avail.
1.) How do I definitively determine the region of my azure bing resource?
2.) Why can I not get around this error with a valid subscription key and the valid region? I tested all regions, one of them had to be correct.
FYI - Once I can get the reco working on this, I will be porting this code to Xamarin.
That usually means doing a binding library for the .aar and referencing it that way.
Please advise if this is the easiest path. It seems that the NuGet package out there was geared to C# and not necc Xamarin.
x)- [X ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)
Build and deploy to a samsung S2 tablet
click the recognize button
view error
>
09-19 15:38:24.108 27054-27054/? E/Zygote: v2
09-19 15:38:24.109 27054-27054/? I/libpersona: KNOX_SDCARD checking this for 10519
KNOX_SDCARD not a persona
09-19 15:38:24.109 27054-27054/? E/Zygote: accessInfo : 0
09-19 15:38:24.110 27054-27054/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2], Con:u:r:zygote:s0 RAM:SEPF_SECMOBILE_7.0_0010, [-1 -1 -1 -1 0 1]
09-19 15:38:24.111 27054-27054/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.microsoft.cognitiveservices.speech.samples.sdkdemo
09-19 15:38:24.113 27054-27054/? I/art: Late-enabling -Xcheck:jni
09-19 15:38:24.149 27054-27054/? D/TimaKeyStoreProvider: TimaKeyStore is not enabled: cannot add TimaSignature Service and generateKeyPair Service
09-19 15:38:24.277 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo I/InstantRun: starting instant run server: is main process
09-19 15:38:24.341 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
09-19 15:38:24.412 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/TextView: setTypeface with style : 0
09-19 15:38:24.413 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/TextView: setTypeface with style : 0
09-19 15:38:24.441 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/TextView: setTypeface with style : 0
09-19 15:38:24.444 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/TextView: setTypeface with style : 0
09-19 15:38:24.446 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/TextView: setTypeface with style : 0
09-19 15:38:24.447 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/TextView: setTypeface with style : 0
09-19 15:38:24.449 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/TextView: setTypeface with style : 0
09-19 15:38:24.531 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/ViewRootImpl@8692e94[MainActivity]: ThreadedRenderer.create() translucent=false
09-19 15:38:24.536 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/InputTransport: Input channel constructed: fd=76
09-19 15:38:24.536 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/ViewRootImpl@8692e94[MainActivity]: setView = DecorView@b721d3d[MainActivity] touchMode=true
09-19 15:38:24.558 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/ViewRootImpl@8692e94[MainActivity]: dispatchAttachedToWindow
09-19 15:38:24.605 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/ViewRootImpl@8692e94[MainActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][1536,2048] result=0x27 surface={isValid=true 547617089024} surfaceGenerationChanged=true
mHardwareRenderer.initialize() mSurface={isValid=true 547617089024} hwInitialized=true
09-19 15:38:24.605 27054-27072/com.microsoft.cognitiveservices.speech.samples.sdkdemo I/Adreno: QUALCOMM build : e488ad0, Ie9c95840c4
Build Date : 10/11/17
OpenGL ES Shader Compiler Version: XE031.09.00.03
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.BR.1.3.6.C1_RB1.07.00.00.267.008
Remote Branch : NONE
Reconstruct Branch : NOTHING
09-19 15:38:24.610 27054-27072/com.microsoft.cognitiveservices.speech.samples.sdkdemo I/OpenGLRenderer: Initialized EGL, version 1.4
09-19 15:38:24.610 27054-27072/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/OpenGLRenderer: Swap behavior 1
09-19 15:38:24.635 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
09-19 15:38:24.659 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/ViewRootImpl@8692e94[MainActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1536, 2048) ci=Rect(0, 48 - 0, 0) vi=Rect(0, 48 - 0, 0) or=1
MSG_WINDOW_FOCUS_CHANGED 1
mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 547617089024}
09-19 15:38:24.660 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@8224765 nm : com.microsoft.cognitiveservices.speech.samples.sdkdemo ic=null
09-19 15:38:24.660 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
09-19 15:38:24.668 27054-27068/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/InputTransport: Input channel constructed: fd=79
09-19 15:38:24.681 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/ViewRootImpl@8692e94[MainActivity]: Relayout returned: oldFrame=[0,0][1536,2048] newFrame=[0,0][1536,2048] result=0x1 surface={isValid=true 547617089024} surfaceGenerationChanged=false
09-19 15:38:24.687 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@5775c3a nm : com.microsoft.cognitiveservices.speech.samples.sdkdemo ic=null
09-19 15:38:29.008 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/ViewRootImpl@8692e94[MainActivity]: ViewPostImeInputStage processPointer 0
09-19 15:38:29.015 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo V/BoostFramework: mAcquireFunc method = public int com.qualcomm.qti.Performance.perfLockAcquire(int,int[])
mReleaseFunc method = public int com.qualcomm.qti.Performance.perfLockRelease()
mAcquireTouchFunc method = public int com.qualcomm.qti.Performance.perfLockAcquireTouch(android.view.MotionEvent,android.util.DisplayMetrics,int,int[])
mIOPStart method = public int com.qualcomm.qti.Performance.perfIOPrefetchStart(int,java.lang.String)
mIOPStop method = public int com.qualcomm.qti.Performance.perfIOPrefetchStop()
09-19 15:38:29.020 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@36786f4
09-19 15:38:29.107 27054-27054/com.microsoft.cognitiveservices.speech.samples.sdkdemo D/ViewRootImpl@8692e94[MainActivity]: ViewPostImeInputStage processPointer 1
09-19 15:38:30.401 27054-27080/com.microsoft.cognitiveservices.speech.samples.sdkdemo I/reco 1: Recognizer returned: Recognition failed with Canceled. Did you enter your subscription?
WebSocket Upgrade failed with an authentication error (401). Please check the subscription key or the authorization token, and the region name.
>
speech to text recognition would occur
Windows 10 running Android Studio 3.1.4 => deploying to Samsung T713 S2 tablet running Android 7.0
>
Thanks! We'll be in touch soon.
the speech sdk is the sdk to the new unified speech service:
https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/
this describes how to get the subscription key:
https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started
it also states for the free keys:
All free trial subscriptions are in the West US region. When you make requests, be sure to use the westus endpoint.
it also generally describes how to set / find regions for keys you created
global is not an available region. All currently available regions are listed here:
https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/regions
thx
Wolfgang
Wolfgang,
I already had a Bing resource, but I created a new one in the interest of being thorough.
I copied down its Subscription Key ('Key1') and made sure to make the region 'eastus'
I tested both
cognitive-services-speech-sdk/quickstart/java-android/
AND
cognitive-services-speech-sdk/samples/java/android/sdkdemo/
Using my new key and new region.
Same result, they are returning canceled. Complaining about the keys and/or region.
Any chance you could pull down the repo, build and test to see if you have the same results?
Im guessing that you already have a Bing Resource that you could use as a guinea pig.'
Any help will be appreciated.
what do you mean by Bing Resource?
You need to get the key for the Speech Service Preview... you did that?
here are easy steps to validate your key / region against the service, without using the SDK:
https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/troubleshooting
When I say Bing Resource I mean
Clicking 'Cognitive Services'
clicking 'Add'
Choosing 'Bing Speech'
Giving it a name
Choosing A Resource Group (new)
Choosing the region.
I have used that powershell script for testing and it failed.
Attached you will find three images
1.) Service or resources list
2.) The 'Keys' page where I got the key (omitted for security of course)
3.) The result of running the powershell script using the key and the known region of eastus
Unless I am grabbing the wrong key, there is an issue with either the Azure account or the SDK.

I figured it out.
I was using the keys from the Bing Speech resource. That was the OLD Bing Speech.
The new 'Speech Services' are completely different. It bundles together Bong Speech with other services, but has different keys.
TLDR; Wrong KEYS
Thank you for posting the screen shots.
this looks like a bing speech key ... this doesn't work ...
your reply just popped up ;)
thanks for updating ...
please open a new issue if you run into more problems
thx
Wolfgang
@wolfma61
this describes how to get the subscription key:
https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started
it also states for the free keys:
All free trial subscriptions are in the West US region. When you make requests, be sure to use the westus endpoint.
The page you referenced no longer mentions that restriction for the free trial subscriptions, but it still holds true. I originally had the region as westeurope and my key did not work. I recreated the resource in westus, and the sample started working.
Thank you, two plus years later.
Nana email göndermeyin ya vala silmekten yoruldum
Mit freundliche Grüße
Am 25.02.2021 um 19:26 schrieb A. M. Sabuncu notifications@github.com:

@wolfma61https://github.com/wolfma61
this describes how to get the subscription key:
https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started
it also states for the free keys:
All free trial subscriptions are in the West US region. When you make requests, be sure to use the westus endpoint.
The page you referenced no longer mentions that restriction for the free trial subscriptions, but it still holds true. I originally had the region as westeurope and my key did not work. I recreated the resource in westus, and the sample started working.
Thank you, two plus years later.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/51#issuecomment-786108033, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARY2DXJLXAKOZJNBVOUZI3DTA2I3PANCNFSM4FWDL6CQ.
@sabuncu - Can you link me to where you created the resource. Was it a trial or a Speech resource in the F0 Free Tier?
@sabuncu - Can you link me to where you created the resource. Was it a trial or a Speech resource in the F0 Free Tier?
@erhopf
Not sure I understand your request for the link. Everything I am trying out is F0. As I mentioned, the one that did not work was westeurope, the one that does is westus with endpoint: https://westus.api.cognitive.microsoft.com/sts/v1.0/issuetoken
@sabuncu - I just ran a test using a F0 resource in West Europe. It looks like you'll need to preface .api.cognitive with your region.
We'll do a quick pass on the docs to make sure that this is more clear.

@erhopf Thank you. Just curious - how was Postman of help in figuring this out?
@sabuncu - Just a quick way to try multiple endpoints without running code (and it prettifies the response and response headers). I validated in Python as well.