steelejay / LowkeySpeech

Google Speech API in Unity (C#)
44 stars 19 forks source link

Project not working and error is WebException: Error: NameResolutionFailure #1

Closed MuhammadFaizanKhan closed 6 years ago

MuhammadFaizanKhan commented 7 years ago

I have tried your sample and provide the API Key but unfortunately getting this error.

WebException: Error: NameResolutionFailure System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) System.Net.HttpWebRequest.GetRequestStream () GoogleVoiceSpeech.HttpUploadFile (System.String url, System.String file, System.String paramName, System.String contentType) (at Assets/Scripts/GoogleVoiceSpeech.cs:173) GoogleVoiceSpeech.OnGUI () (at Assets/Scripts/GoogleVoiceSpeech.cs:131)

Can you please look into this matter??

steelejay commented 7 years ago

Hi Muhammad, I'm afraid I don't have steady internet right now because of a hurricane. So I can't test what's going on. But, NameResolutionFailure indicates a DNS issue. The URL my code tries for is "http://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=" so if you're unable to resolve google.com (or whatever URL you may be using) you'll get that error.

It's been a while since I've worked on this code so I don't know if the API has changed yet. You may want to try the official Unity Asset they released a couple of months ago that let you experiment with a number of Speech APIs.

https://www.assetstore.unity3d.com/en/#!/content/69399

Good luck!

MuhammadFaizanKhan commented 7 years ago

Sad to hear that you have affected by hurricane. Stay safe and thanks for reply even in this conditions.

I am using google speech to text API. Maybe the url is wrong but unable to find that which is the correct URL. I have tried this so far and error is the same

  1. "http://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key="+ apiKey; (this provide by your code)

  2. "https://speech.googleapis.com/v1/speech:recognize?key=" + apiKey;

  3. "https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=${" + apiKey + "}";

I have posted my qeuestion at stackoverflow and i am unable to understand what the actual URL i use for request. Can you please look into this.

While Unity offical package one month older than your this post and it has different errors and it require several other packages (like UnityWEB, IBMWatson etc) to run (i have already tried that).

MuhammadFaizanKhan commented 7 years ago

I am somehow manage to successfully installed Unity Speech to Text Package but it is showing me this error

UnityException: Speech recognition is not supported on this machine. UnityEngine.Windows.Speech.DictationRecognizer.Create (ConfidenceLevel minimumConfidence, DictationTopicConstraint topicConstraint) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/SpeechBindings.gen.cs:92) UnityEngine.Windows.Speech.DictationRecognizer..ctor (ConfidenceLevel minimumConfidence, DictationTopicConstraint topic) (at C:/buildslave/unity/build/Runtime/Export/Windows/Speech.cs:303) UnitySpeechToText.Services.WindowsSpeechToTextService.Start () (at Assets/SpeechToText/Scripts/SpeechToTextServices/WindowsSpeechToTextService.cs:49)

and the reason is that Unity Speech Class is only supported in windows 10. Your solution maybe feasible if name resoultion become solve. Can you please look into this matter.

steelejay commented 7 years ago

Thanks for the kind words, Muhammad. You're quite welcome, I'm very fortunate that the storm didn't hit my area too badly.

The URL you use with my code should take the format of the first one, I'm reasonably confident in that. I just tried testing myself, but my internet connection isn't stable enough to upload. I'll double check once it comes back though.

I think you may be having DNS issues based on your location? I see you're in Pakistan and I wonder if you might need to use a domain that's more localized? www.google.com.pk maybe? I would first try doing a traceroute or nslookup on www.google.com and speech.googleapis.com and see if that resolves properly. If they don't then you definitely need to find a different domain to use. At that point you may be better off trying to get the attention of someone at google directly. You can try here: https://groups.google.com/forum/#!forum/cloud-speech-discuss

Or perhaps see if there's a localized version of google groups available to you at the .com.pk domain. https://groups.google.com.pk/forum/#!forum/cloud-speech-discuss I tried myself but it only redirected me back to the US version.

MuhammadFaizanKhan commented 7 years ago

Wait i am using internet with proxy. Can this be a problem?

steelejay commented 7 years ago

Yes! :) That could be an issue. I don't know if my code would work through that. I've no idea if System.Net will automatically use your proxy settings or if you have to manually insert your proxy URL before the Google API URL. How you would do that would be dependent on the proxy setup you're using.

MuhammadFaizanKhan commented 7 years ago

Yes, that was the problem :). Now, the second problem i am getting this

WebException: The remote server returned an error: (403) Forbidden. System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data)

I request in this url (as given by your code) http://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=" + apiKey;

while other url error is

WebException: Error writing request: The authentication or decryption has failed. System.Net.WebConnectionStream.WriteHeaders () System.Net.WebConnectionStream.SetHeaders (System.Byte[] buffer) (wrapper remoting-invoke-with-check) System.Net.WebConnectionStream:SetHeaders (byte[]) System.Net.HttpWebRequest.SendRequestHeaders (Boolean propagate_error)

Remember i didn't purchased Google Speech To Text API yet. And Thanks for your this effort. IMO you should make package of your code and sell it at asset store. Anyway thanks again.

steelejay commented 7 years ago

Awesome. Progress! ;)

Okay, so I can confirm that the code still works. I got my internet back this morning and tested it out without issue. I'm going to attach the wav file I used and what you can do is download it and let the code upload it to google by replacing filePath with a string containing the path of this wav file.

testing1.661563.zip

Response = HttpUploadFile (apiURL, "filepath string goes here", "file", "audio/wav; rate=44100");

The reason we're going to try this is the API doesn't really give you any information back about why it doesn't want to work and its very picky about the files it will accept. We know this one works. Let's see what happens.

You don't need Speech to Text API yet, this is for the Speech API which is free for personal and development use up to... I think 50 queries in a 24 hour period.

You should probably also go here and double check that your project is authorized for the Speech API. If you don't see it listed I think you can enable it from the Google APIs tab. You may need to select a project to get that link to work. If you have to manually navigate your way there it's console.cloud.google.com -> Library -> Private APIs

Thanks for the kind words. I may make an asset out of it, but I don't want to sell it as if it wasn't for all the free stuff out there that I learned from I wouldn't be where I am today. I hope to give back more than what I got. :D

steelejay commented 7 years ago

Muhammad, were you able to get it working? Can I close this issue?

thexiroy commented 7 years ago

Hello I have read through your conversation with Muhammad, I think I have the same problem, I added my own apiKey and also getting error 403.

No proxy, I live in The Netherlands and I have tried your .wav file

steelejay commented 7 years ago

Hi, thexiroy.

403 even with that wav file? Hmm. So it's not your file. Did you double check in the console to make sure that your project is authorized for the speech api? Also, ensure that your language setting is correct for the language being used.

So for that test file you'll want to use: http://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=" + apiKey;

But for Dutch (Netherlands) you'll want to use: http://www.google.com/speech-api/v2/recognize?output=json&lang=nl-NL&key=" + apiKey;

While Muhammad should be trying with Urdu (Pakistan): http://www.google.com/speech-api/v2/recognize?output=json&lang=ur-PK&key=" + apiKey;

Speaking from personal experience, using a tool like wireshark can also be handy to sniff your traffic and ensure that the file is being transferred properly.

Good luck and please keep me informed.

MuhammadFaizanKhan commented 7 years ago

Hi Steelejay, I am not trying with Urdu, I am trying with English. I found that if you want to use free/trail of google speech API then you (still) have to provide your credit card details. This seems risky thats why i am unable to get new key. (Thexiroy did you find the key )

thexiroy commented 7 years ago

@MuhammadFaizanKhan Yes I have a key, I work on a project for a company where they provided me with a google account with a linked credit card.

@steelejay Google speech API is enabled and I have generated a key (even added an IP for security reasons). As for a language setting, I was unable to find one. This is my first project with a Google API so I have yet to learn their tools and options. (like their console) I am not great with wireshark, I will give it a try.

Sorry for my late response had a lot going on which made me unable to work further. I appreciate your help.

thexiroy commented 7 years ago

Ok, I am almost certain that there is something wrong with my key, though I have no idea what the problem is. Tried a different project with similar webrequest code, tried to simply put the url in the browser. Every time I get error 403 with the message "Invalid key. That’s all we know." The same message was also displayed in Wireshark. I have tried generating new keys and removing restrictions but it has no effect.

steelejay commented 7 years ago

@MuhammadFaizanKhan, that wasn't the case when i signed up. Disappointing.

@thexiroy Perhaps you'll find more help here? https://groups.google.com/forum/#!forum/cloud-speech-discuss

I'm afraid there's not much more I can think of. You're definitely using the Speech API not Speech to Text API, right?

steelejay commented 6 years ago

I'm going to go ahead and close this out. I think we've established that the code works, but there's some hoops to jump through getting the api key working properly. Take care.