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

HTTP response status is 200 but content is empty #42

Open
yanxuceo opened this issue Dec 31, 2021 · 5 comments
Open

HTTP response status is 200 but content is empty #42

yanxuceo opened this issue Dec 31, 2021 · 5 comments

Comments

@yanxuceo
Copy link

yanxuceo commented Dec 31, 2021

Hi Chris, thank you so much for this open source project. You might have heard my voice if you checked your wit.ai app for this project.

I set up my hardware and flashed this code, then it works well for "Marvin" wake-up and following "tell me a joke" "what's the life" command.

The issue is:
But when I replace the URL and access_key with my settings(which works well with curl and my local recorded .wav samples), I don't get the expected JSON content, I added this debugging line in getResults(), but the returned entities, intents and text are all empty.

if (status == 200) { char temp[1024]; int read_cnt = m_wifi_client->readBytes(temp, 1024); Serial.printf("Http str is: %s\n", temp); }

Do you possibly have any clue? I am really confused since the only difference is the replacement with my wit.ai settings. And in my app, I did receive the recorded and uploaded voice sample. But it seems that the HTTP response got something wrong.

Thank you so much for any guidance for debugging.

Best regards,
Xu

@yanxuceo
Copy link
Author

yanxuceo commented Jan 1, 2022

I see, it's because now(with an update in October 2021) the /speech endpoint returns partial transcripts, which is mentioned in this issue:
wit-ai/wit#2206

@cgreening
Copy link
Contributor

That's annoying. I guess we can apply the fix mentioned in that issue. I wonder why they changed it?

@yanxuceo
Copy link
Author

yanxuceo commented Jan 1, 2022

Hi Chris,

thanks for the quick reply. I am new to the web stuff, but I will try to fix it. But do you have some idea, why this update has no effect on your wit.ai app(everything works well with your acess_key)? Does this API update only apply to newly created app?

Or actually your code already handles it correctly, I might make something wrong with my configuration...

I really appreciate your help.

Best regards,
Xu

@cgreening
Copy link
Contributor

Hi Xu,

I need to plug mine back together - it got taken apart for a new project and I need to re-assemble it.

I'll have a look this weekend as it sounds like a simple fix.

Best
Chris

@yanxuceo
Copy link
Author

yanxuceo commented Jan 1, 2022

Hi Chris, I just learned and fixed something. This is what I get on Terminal when I run:

$ curl -XPOST 'https://api.wit.ai/speech?v=20211231' -i -L -H "Authorization: Bearer my_access_key" -H "Content-Type: audio/wav" --data-binary "@apple.wav"

JSON return:
HTTP/1.1 100 Continue
Date: Sat, 01 Jan 2022 12:29:54 GMT

HTTP/1.1 200 OK
Content-Type: application/json
Date: Sat, 01 Jan 2022 12:29:54 GMT
Transfer-Encoding: chunked
Connection: keep-alive

{
"text": "Hey"
}
{
"text": "Hey Facebook"
}
{
"text": "This is Apple."
}
{
"entities": {
"fruit_type:fruit_type": [
{
//ignored
}
]
},
"intents": [
{
//ignored
}
],
"text": "This is Apple.",
"traits": {}

For this chunked return, there is no "Content-Length" in the header part. Then in the code, I added these lines in if(status == 200), which I learned from Arduino community:

    String chunk = "";
    int limit = 1;
    String response="";

    Serial.println(response);
    do {
         if (m_wifi_client->connected()) {
            m_wifi_client->setTimeout(4000);
            chunk = m_wifi_client->readStringUntil('\n');
            response += chunk;
            Serial.println(chunk);
        }
    } while (chunk.length() > 0 && ++limit < 1000);

Then, I see exact the same JSON return as it is with above curl command. So happy to see this work! I will continue to work on the deserializeJson() part. Looking forward to your fix. Thank you.

Best regards,
Xu

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

No branches or pull requests

2 participants