語音 SDK 會整合 Microsoft 音訊堆疊 (MAS),讓任何應用程式或產品都可以在輸入音訊上使用其音訊處理功能。 如需概觀,請參閱音訊處理文件。
在本文中,您會了解如何搭配使用 Microsoft 音訊堆疊 (MAS) 與語音 SDK。
重要
在適用於 C++ 和 C# v1.33.0 和更新版本的語音 SDK 上,您必須在 Windows 上安裝 Microsoft.CognitiveServices.Speech.Extension.MAS 套件,才能使用 Microsoft 音訊堆疊,如果您使用 NuGet 安裝語音 SDK,則需在 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);