How can I use Azure speech to recognize audio stream with c++, is there any samples?

klen 21 Reputation points
2021-01-08T07:55:21.65+00:00

I have two questions:
1 From
I did not find sample about audio stream.

2 I have replaced scriptionKey and ServiceRegion, and subscribed Speech Service, I tried this
std::string FILE_NAME = "./myVoiceIsMyPassportVerifyMe03.wav";

void recognizeSpeech() {
    // Creates an instance of a speech config with specified subscription key and service region.
    // Replace with your own subscription key and service region (e.g., "westus").
    using namespace Microsoft::CognitiveServices::Speech::Audio;

    auto config = SpeechConfig::FromSubscription("myid", "myreg");
    auto audioInput = AudioConfig::FromWavFileInput(FILE_NAME);
    auto recognizer = SpeechRecognizer::FromConfig(config, audioInput);
    auto result = recognizer->RecognizeOnceAsync().get();
    switch (result->Reason)
    {
        case ResultReason::RecognizedSpeech:
            cout << "We recognized: " << result->Text << std::endl;
            break;
        case ResultReason::NoMatch:
            cout << "NOMATCH: Speech could not be recognized." << std::endl;
            break;
        case ResultReason::Canceled:
            {
                auto cancellation = CancellationDetails::FromResult(result);
                cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;

                if (cancellation->Reason == CancellationReason::Error) {
                    cout << "CANCELED: ErrorCode= " << (int)cancellation->ErrorCode << std::endl;
                    cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
                    cout << "CANCELED: Did you update the subscription info?" << std::endl;
                }
            }
            break;
        default:
            break;
    }
}

but I got
CANCELED: Reason=1
CANCELED: ErrorCode= 5
CANCELED: ErrorDetails=Connection failed (no connection to the remote host). Internal error: 1. Error details: Code: 2460. SessionId: 16230b52f1a9435a97a65a0ff4dbc26e
CANCELED: Did you update the subscription info?

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,519 questions
0 comments No comments
{count} votes

Accepted answer
  1. romungi-MSFT 43,656 Reputation points Microsoft Employee
    2021-01-08T12:14:16.363+00:00

    @klen With respect to the second question are you using the correct subscription id and region of your Azure speech resource since the error seems to indicate it cannot connect to the remote host? Also, I think you can simply pass your file name as myVoiceIsMyPassportVerifyMe03.wav as you are using the windows from-file code sample.

    The samples for CPP audio stream are available in the samples folder instead of the quickstart.


1 additional answer

Sort by: Most helpful
  1. romungi-MSFT 43,656 Reputation points Microsoft Employee
    2021-01-08T14:06:56.383+00:00

    @klen from the setup of SDK documentation centos is supported.

    The Speech SDK only supports Ubuntu 16.04/18.04/20.04, Debian 9/10, Red Hat Enterprise Linux (RHEL) 7/8, and CentOS 7/8 on the following target architectures when used with Linux:

    Linux

    • x86 (Debian/Ubuntu), x64, ARM32 (Debian/Ubuntu), and ARM64 (Debian/Ubuntu) for C++ development
    • x64, ARM32 (Debian/Ubuntu), and ARM64 (Debian/Ubuntu) for Java
    • x64, ARM32 (Debian/Ubuntu), and ARM64 (Debian/Ubuntu) for .NET Core
    • x64 for Python

    The changes required to this code are only updating the subscription key of your speech resource and region along with the filename or path.
    I think you may be missing the openssl libraries which is also mentioned in this document to setup the speech SDK for centos.