언어
Important
Windows ML 런타임 및 음성 인식 API는 현재 실험적이며 프로덕션 환경에서 사용하도록 지원되지 않습니다. 이러한 API를 사용해보는 앱은 Microsoft Store에 게시해서는 안 됩니다.
Important
Windows ML 런타임 및 음성 인식 API는 현재 C++ 및 Python에서 사용할 수 있으며; C#은 현재 지원되지 않습니다. Windows ML GitHub 리포지토리에 문제를 게시하여 C#에서 이러한 API를 사용하는 데 관심이 있는지 알려주세요.
Windows ML Speech Recognition API는 사용자 고유의 위스퍼 모델을 사용해 ASR(자동 음성 인식) 실행을 간소화합니다. 위스퍼 인코더 파이프라인, 디코더 파이프라인 및 토크나이저를 구성한 다음, Windows ML 런타임 API를 기반으로 자동 회귀 전사 루프, 스트리밍 출력 및 취소를 대신 처리합니다. Windows는 이 API에 대한 모델을 기본 제공하지 않습니다. 앱과 함께 위스퍼 모델(인코더 및 디코더 파일, 그리고 토크나이저)을 선택, 패키징 및 배포합니다.
Tip
특정 위스퍼 모델 또는 사용자 지정 배포가 필요하지 않고 Microsoft 관리하는 모델을 사용하여 디바이스에서 음성 텍스트 변환만 하려면 즉시 사용할 수 있는 Speech Recognition API를 대신 사용하세요.
인코더 및 디코더 모델, 실행 대상 및 파이프라인과 같은 기본 런타임 개체를 만들고 세션에 전달합니다. API는 하드웨어 배치를 숨기지 않습니다. 직접 디코드 루프를 작성할 필요만 없앨 뿐입니다.
지원되는 모델
Speech Recognition API는 위스퍼 인코더/디코더 아키텍처용으로 특별히 빌드되었습니다. 일반 ASR API가 아닙니다. 제공 항목:
-
ONNX 인코더 및 디코더 모델(
encoder_model.onnx및decoder_model.onnx)을 ONNX Runtime을 통해 실행
tokenizer 파일은 인코더/디코더 쌍과 함께 제공됩니다. 입력 텐서에는 모노 부동 소수점 PCM 샘플과 샘플레이트 및 유효한 길이 메타데이터가 포함됩니다.
오디오 전사하기
파형 샘플을 보유하는 런타임 텐서를 제공합니다. 위스퍼 인코더 및 디코더 모델을 로드하고, 각각에 대한 파이프라인을 빌드하고, 토크나이저와 함께 세션으로 구성합니다.
// Create the runtime and an execution target (CPU here; GPU/NPU also available).
ComPtr<IWinMLRuntime> runtime;
THROW_IF_FAILED(WinMLCreateRuntime(IID_PPV_ARGS(runtime.GetAddressOf())));
ComPtr<IWinMLExecutionTarget> target;
THROW_IF_FAILED(runtime->CreateCpuExecutionTarget(target.GetAddressOf()));
// Load the Whisper encoder as its own single-stage pipeline.
ComPtr<IWinMLModel> encoderModel;
THROW_IF_FAILED(runtime->LoadModelFromFile(
L"C:\\models\\whisper\\encoder_model.onnx", nullptr, encoderModel.GetAddressOf()));
ComPtr<IWinMLPipelineBuilder> encoderBuilder;
THROW_IF_FAILED(runtime->CreatePipelineBuilder(encoderBuilder.GetAddressOf()));
ComPtr<IWinMLStage> encoderStage;
THROW_IF_FAILED(encoderBuilder->AddModelStage(
encoderModel.Get(), target.Get(), L"whisper-encoder", encoderStage.GetAddressOf()));
ComPtr<IWinMLPipeline> encoderPipeline;
THROW_IF_FAILED(encoderBuilder->Build(encoderPipeline.GetAddressOf()));
// Load the Whisper decoder the same way.
ComPtr<IWinMLModel> decoderModel;
THROW_IF_FAILED(runtime->LoadModelFromFile(
L"C:\\models\\whisper\\decoder_model.onnx", nullptr, decoderModel.GetAddressOf()));
ComPtr<IWinMLPipelineBuilder> decoderBuilder;
THROW_IF_FAILED(runtime->CreatePipelineBuilder(decoderBuilder.GetAddressOf()));
ComPtr<IWinMLStage> decoderStage;
THROW_IF_FAILED(decoderBuilder->AddModelStage(
decoderModel.Get(), target.Get(), L"whisper-decoder", decoderStage.GetAddressOf()));
ComPtr<IWinMLPipeline> decoderPipeline;
THROW_IF_FAILED(decoderBuilder->Build(decoderPipeline.GetAddressOf()));
ComPtr<IWinMLTokenizer> tokenizer;
THROW_IF_FAILED(WinMLCreateTokenizerFromFile(
L"C:\\models\\whisper\\tokenizer.json", tokenizer.GetAddressOf()));
// Compose the encoder/decoder pipelines and tokenizer into a session.
const winml::tasks::speech::asr::AutomaticSpeechRecognitionArguments arguments{
runtime.Get(),
tokenizer.Get(),
{
encoderPipeline.Get(),
encoderStage.Get(),
decoderPipeline.Get(),
decoderStage.Get(),
target.Get(),
},
};
winml::tasks::speech::asr::AutomaticSpeechRecognition speechRecognition;
THROW_IF_FAILED(winml::tasks::speech::asr::BuildAutomaticSpeechRecognition(
arguments, speechRecognition));
TranscribeWaveform을 호출하여 스트리밍 작업을 시작한 다음, 완료가 보고될 때까지 반환된 스트림에서 조각을 가져옵니다.
ComPtr<IWinMLCancellationSource> cancellation;
THROW_IF_FAILED(speechRecognition.tasks->CreateCancellationSource(
cancellation.GetAddressOf()));
ComPtr<IWinMLAutomaticSpeechRecognitionPullStream> stream;
THROW_IF_FAILED(speechRecognition.session->TranscribeWaveform(
waveform.Get(),
&waveformMetadata,
cancellation.Get(),
stream.GetAddressOf()));
// Pull transcript text one fragment at a time until the stream completes.
WINML_AUTOMATIC_SPEECH_RECOGNITION_READ_STATUS status{};
LPCWSTR fragment = nullptr;
while (SUCCEEDED(stream->ReadNext(&status, &fragment)) &&
status == WINML_AUTOMATIC_SPEECH_RECOGNITION_READ_STATUS_UPDATE)
{
std::wprintf(L"%ls", fragment);
}
// The terminal result is the authoritative transcript and finish reason.
ComPtr<IWinMLAutomaticSpeechRecognitionResult> result;
THROW_IF_FAILED(stream->GetResult(result.GetAddressOf()));
waveform 및 waveformMetadata는 사용자 고유의 오디오 로드 코드에서 제공됩니다. 즉, 모노 부동 소수점 PCM 샘플을 담고 있는 Runtime 텐서와 이를 설명하는 샘플 속도 및 유효 길이 메타데이터입니다.
완료된 결과는 전체 대본 및 완료 이유(예: 기록 종료 토큰, 취소 또는 오류)를 보고합니다.
C++ 및 Python
네이티브 API는 winml/tasks/speech/asr/WhisperAutomaticSpeechRecognition.hpp를 통해 노출되며, 형식화된 C++ 도우미는 WinMLTasks.h 아래에 있습니다. Python 애플리케이션은 windowsml.tasks 프로젝션을 windowsml.runtime와 함께 사용합니다.
Windows ML 샘플에는 C++ 및 Python 위스퍼 전사 샘플이 포함됩니다. 이 샘플에서는 추상화가 시작되는 위치와 기반 워크플로를 사용자 지정하는 방법을 확인할 수 있도록 음성 인식 구성 옆에 전체 런타임 설정을 보여 줍니다.
또한, 다음을 참조하세요.
- Windows AI API를 사용한 음성 인식(즉시 사용 가능한 Microsoft 관리형 모델)
- Windows ML 런타임 API 개요
- Windows ML 런타임 API 개념
- Windows ML 텍스트 생성 API를 사용하여 텍스트 생성
- Windows ML 샘플