语音 SDK 集成 Microsoft 音频堆栈 (MAS),允许任何应用程序或产品对输入音频使用其音频处理功能。 有关概述,请参阅音频处理文档。
本文介绍如何将 Microsoft 音频堆栈 (MAS) 与语音 SDK 结合使用。
重要
在适用于 C++ 和 C# v1.33.0 及更高版本的语音 SDK 上,必须安装 Microsoft.CognitiveServices.Speech.Extension.MAS 包才能在 Windows 上使用 Microsoft 音频堆栈;如果你使用 NuGet 来安装语音 SDK,则必须在 Linux 上使用 Linux 音频堆栈。
var speechConfig = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
var audioProcessingOptions = AudioProcessingOptions.Create(AudioProcessingConstants.AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT);
var audioInput = AudioConfig.FromDefaultMicrophoneInput(audioProcessingOptions);
var recognizer = new SpeechRecognizer(speechConfig, audioInput);
auto speechConfig = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");
auto audioProcessingOptions = AudioProcessingOptions::Create(AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT);
auto audioInput = AudioConfig::FromDefaultMicrophoneInput(audioProcessingOptions);
auto recognizer = SpeechRecognizer::FromConfig(speechConfig, audioInput);
var speechConfig = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
var audioProcessingOptions = AudioProcessingOptions.Create(AudioProcessingConstants.AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT, PresetMicrophoneArrayGeometry.Linear2);
var audioInput = AudioConfig.FromMicrophoneInput("hw:0,1", audioProcessingOptions);
var recognizer = new SpeechRecognizer(speechConfig, audioInput);
auto speechConfig = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");
auto audioProcessingOptions = AudioProcessingOptions::Create(AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT, PresetMicrophoneArrayGeometry::Linear2);
auto audioInput = AudioConfig::FromMicrophoneInput("hw:0,1", audioProcessingOptions);
auto recognizer = SpeechRecognizer::FromConfig(speechConfig, audioInput);
var speechConfig = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
MicrophoneCoordinates[] microphoneCoordinates = new MicrophoneCoordinates[7]
{
new MicrophoneCoordinates(0, 0, 0),
new MicrophoneCoordinates(40, 0, 0),
new MicrophoneCoordinates(20, -35, 0),
new MicrophoneCoordinates(-20, -35, 0),
new MicrophoneCoordinates(-40, 0, 0),
new MicrophoneCoordinates(-20, 35, 0),
new MicrophoneCoordinates(20, 35, 0)
};
var microphoneArrayGeometry = new MicrophoneArrayGeometry(MicrophoneArrayType.Planar, microphoneCoordinates);
var audioProcessingOptions = AudioProcessingOptions.Create(AudioProcessingConstants.AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT, microphoneArrayGeometry, SpeakerReferenceChannel.LastChannel);
var audioInput = AudioConfig.FromWavFileInput("katiesteve.wav", audioProcessingOptions);
var recognizer = new SpeechRecognizer(speechConfig, audioInput);
var speechConfig = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
var audioProcessingOptions = AudioProcessingOptions.Create(AudioProcessingConstants.AUDIO_INPUT_PROCESSING_DISABLE_ECHO_CANCELLATION | AudioProcessingConstants.AUDIO_INPUT_PROCESSING_DISABLE_NOISE_SUPPRESSION | AudioProcessingConstants.AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT);
var audioInput = AudioConfig.FromDefaultMicrophoneInput(audioProcessingOptions);
var recognizer = new SpeechRecognizer(speechConfig, audioInput);
auto speechConfig = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");
auto audioProcessingOptions = AudioProcessingOptions::Create(AUDIO_INPUT_PROCESSING_DISABLE_ECHO_CANCELLATION | AUDIO_INPUT_PROCESSING_DISABLE_NOISE_SUPPRESSION | AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT);
auto audioInput = AudioConfig::FromDefaultMicrophoneInput(audioProcessingOptions);
auto recognizer = SpeechRecognizer::FromConfig(speechConfig, audioInput);
var speechConfig = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
MicrophoneCoordinates[] microphoneCoordinates = new MicrophoneCoordinates[4]
{
new MicrophoneCoordinates(-60, 0, 0),
new MicrophoneCoordinates(-20, 0, 0),
new MicrophoneCoordinates(20, 0, 0),
new MicrophoneCoordinates(60, 0, 0)
};
var microphoneArrayGeometry = new MicrophoneArrayGeometry(MicrophoneArrayType.Linear, 70, 110, microphoneCoordinates);
var audioProcessingOptions = AudioProcessingOptions.Create(AudioProcessingConstants.AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT, microphoneArrayGeometry, SpeakerReferenceChannel.LastChannel);
var pushStream = AudioInputStream.CreatePushStream();
var audioInput = AudioConfig.FromStreamInput(pushStream, audioProcessingOptions);
var recognizer = new SpeechRecognizer(speechConfig, audioInput);