【问题标题】:C++ 'speechapi_cxx.h': No such file or directory Visual StudioC++'speechapi_cxx.h':没有这样的文件或目录 Visual Studio
【发布时间】:2020-05-24 05:12:57
【问题描述】:

我正在 Visual Studio 2019 上尝试语音转文本功能。我在 Microsoft 网站上找到了此代码,但编译器显示“speechapi_cxx.h”:没有这样的文件或目录。

.................................................. .........................

#include <iostream> // cin, cout
#include <speechapi_cxx.h>

using namespace std;
using namespace Microsoft::CognitiveServices::Speech;

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").
    auto config = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");

    // Creates a speech recognizer
    auto recognizer = SpeechRecognizer::FromConfig(config);
    cout << "Say something...\n";

    // Starts speech recognition, and returns after a single utterance is recognized. The end of a
    // single utterance is determined by listening for silence at the end or until a maximum of 15
    // seconds of audio is processed.  The task returns the recognition text as result. 
    // Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
    // shot recognition like command or query. 
    // For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
    auto result = recognizer->RecognizeOnceAsync().get();

    // Checks result.
    if (result->Reason == ResultReason::RecognizedSpeech) {
        cout << "We recognized: " << result->Text << std::endl;
    }
    else if (result->Reason == ResultReason::NoMatch) {
        cout << "NOMATCH: Speech could not be recognized." << std::endl;
    }
    else if (result->Reason == 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;
        }
    }
}

int main(int argc, char** argv) {
    setlocale(LC_ALL, "");
    recognizeSpeech();
    return 0;
}

【问题讨论】:

  • 您缺少包含在 #include &lt;speechapi_cxx.h&gt; 中的标头。这是因为您缺少必要的库。你确定你正确安装了SDK吗?下次,如果您提供指向您尝试使用的 API 的链接,将会很有帮助。

标签: c++ speech-recognition visual-studio-2019 text-to-speech speech-to-text


【解决方案1】:

您的机器上没有安装语音 SDK。你可以在这里下载它https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/speech-sdk

【讨论】:

  • 或者没有正确安装,或者VS没有正确配置找到它等等
猜你喜欢
  • 1970-01-01
  • 2020-04-28
  • 1970-01-01
  • 1970-01-01
  • 2020-04-07
  • 1970-01-01
  • 2022-01-16
  • 2014-02-25
  • 1970-01-01
相关资源
最近更新 更多