Speech-to-Text v1에서 v2로 마이그레이션

Speech-to-Text API v2는 고객이 엔터프라이즈 보안 및 규제 요구사항을 즉시 충족할 수 있도록 최신 Google Cloud API 디자인을 제공합니다.

이러한 요구사항은 다음을 통해 구현됩니다.

  • 데이터 상주: Speech-to-Text v2는 Google Cloud 리전(예: 벨기에 또는 싱가포르)에서 다양한 기존 스크립트 작성 모델을 제공합니다. 이러한 모델을 사용하면 완전히 리전화된 서비스를 통해 스크립트 작성 모델을 호출할 수 있습니다.

  • 인식기 리소스 많음: 인식기는 모델, 언어, 기능의 조합을 포함할 수 있는 재사용 가능한 인식 구성입니다. 이러한 리소스 구현으로 인해 인증 및 승인에 전용 서비스 계정이 필요하지 않습니다.

  • 로깅: 리소스 생성 및 스크립트 작성은 Google Cloud 콘솔에서 사용 가능한 로그를 생성하므로 원격 분석 및 디버깅을 개선할 수 있습니다.

  • 암호화: Speech-to-Text v2는 일괄 스크립트 작성은 물론 모든 리소스에 대한 고객 관리 암호화 키를 지원합니다.

  • 오디오 자동 감지: Speech-to-Text v2는 요청 구성에 정보를 제공하지 않고도 오디오 파일의 샘플링 레이트, 채널 수, 형식을 자동으로 감지할 수 있습니다.

v1에서 v2로 이전

v1 API에서 v2 API로의 마이그레이션은 자동으로 수행되지 않습니다. 특성 세트를 활용하려면 최소한의 구현 변경이 필요합니다.

API에서 마이그레이션

Speech-to-Text v1과 마찬가지로 오디오 스크립트를 작성하려면 오디오 언어와 인식 모델을 선택하여 RecognitionConfig를 만들어야 합니다.

Python

from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech

def quickstart_v2(
    project_id: str,
    audio_file: str,
) -> cloud_speech.RecognizeResponse:
    """Transcribe an audio file."""
    # Instantiates a client
    client = SpeechClient()

    # Reads a file as bytes
    with open(audio_file, "rb") as f:
        content = f.read()

    config = cloud_speech.RecognitionConfig(
        auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
        language_codes=["en-US"],
        model="long",
    )

    request = cloud_speech.RecognizeRequest(
        recognizer=f"projects/{project_id}/locations/global/recognizers/_",
        config=config,
        content=content,
    )

    # Transcribes the audio into text
    response = client.recognize(request=request)

    for result in response.results:
        print(f"Transcript: {result.alternatives[0].transcript}")

    return response

필요한 경우 Speech-to-Text API를 사용할 리전을 선택하고 이 리전에서 언어 및 모델 가용성을 확인합니다.

Python

from google.api_core.client_options import ClientOptions
from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech

def change_speech_v2_location(
    project_id: str,
    location: str,
    audio_file: str,
) -> cloud_speech.RecognizeResponse:
    """Transcribe an audio file in a specific region."""
    # Instantiates a client to a regionalized Speech endpoint.
    client = SpeechClient(
        client_options=ClientOptions(
            api_endpoint=f"{location}-speech.googleapis.com",
        )
    )

    # Reads a file as bytes
    with open(audio_file, "rb") as f:
        content = f.read()

    config = cloud_speech.RecognitionConfig(
        auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
        language_codes=["en-US"],
        model="long",
    )

    request = cloud_speech.RecognizeRequest(
        recognizer=f"projects/{project_id}/locations/{location}/recognizers/_",
        config=config,
        content=content,
    )

    # Transcribes the audio into text
    response = client.recognize(request=request)

    for result in response.results:
        print(f"Transcript: {result.alternatives[0].transcript}")

    return response

여러 스크립트 작성 요청에서 특정 인식 구성을 재사용해야 하는 경우 인식기 리소스를 만듭니다.

Python

from google.cloud.speech_v2 import SpeechClient
from google.cloud.speech_v2.types import cloud_speech

def create_recognizer(project_id: str, recognizer_id: str) -> cloud_speech.Recognizer:
    # Instantiates a client
    client = SpeechClient()

    request = cloud_speech.CreateRecognizerRequest(
        parent=f"projects/{project_id}/locations/global",
        recognizer_id=recognizer_id,
        recognizer=cloud_speech.Recognizer(
            default_recognition_config=cloud_speech.RecognitionConfig(
                language_codes=["en-US"], model="long"
            ),
        ),
    )

    operation = client.create_recognizer(request=request)
    recognizer = operation.result()

    print("Created Recognizer:", recognizer.name)
    return recognizer

새 v2 API에서는 요청과 응답에 다른 차이가 있습니다. 자세한 내용은 참조 문서를 확인하세요.

UI에서 마이그레이션

Speech Google Cloud 콘솔을 통해 마이그레이션하려면 다음 단계를 수행합니다.

  1. Speech Google Cloud 콘솔로 이동합니다.

  2. 스크립트 작성 페이지로 이동합니다.

  3. 새 스크립트 작성을 클릭하고 오디오 구성 탭에서 오디오를 선택합니다.

  4. 스크립트 작성 옵션 탭에서 V2를 선택합니다.