이 가이드에서는 Google의 Vertex AI Speech 서비스를 사용하여 Speech-to-Text 테스트를 실행하는 과정을 안내합니다.
이 샘플을 사용해 보기 전에 Vertex AI 빠른 시작: 클라이언트 라이브러리 사용의 Python 설정 안내를 따르세요. 자세한 내용은 Vertex AI Python API 참조 문서를 확인하세요.
speech-to-text-test.py
Python 파일을 만듭니다. 다음과 같이image_uri_to_test
값을 소스 이미지의 URI로 바꿉니다.from google.cloud import speech def transcribe_gcs_audio(gcs_uri: str) -> speech.RecognizeResponse: client = speech.SpeechClient() audio = speech.RecognitionAudio(uri=gcs_uri) config = speech.RecognitionConfig( encoding=speech.RecognitionConfig.AudioEncoding.FLAC, sample_rate_hertz=16000, language_code="en-US", # Specify the language code (e.g., "en-US" for US English) # You can add more features here, e.g.: # enable_automatic_punctuation=True, # model="default" # or "latest_long", "phone_call", "video", "chirp" (v2 API) ) # Performs synchronous speech recognition on the audio file response = client.recognize(config=config, audio=audio) # Print the transcription for result in response.results: print(f"Transcript: {result.alternatives[0].transcript}") if result.alternatives[0].confidence: print(f"Confidence: {result.alternatives[0].confidence:.2f}") return response if __name__ == "__main__": # Replace with the URI of your audio file in Google Cloud Storage audio_file_uri = "AUDIO_FILE_URI" print(f"Transcribing audio from: {audio_file_uri}") transcribe_gcs_audio(audio_file_uri)
다음을 바꿉니다.
AUDIO_FILE_URI
: 오디오 파일의 URI입니다('gs://your-bucket/your-image.png
').
Dockerfile 만들기:
ROM python:3.9-slim WORKDIR /app COPY speech-to-text-test.py /app/ # Install 'requests' for HTTP calls RUN pip install --no-cache-dir requests CMD ["python", "speech-to-text-test.py"]
Speech-to-Text 애플리케이션의 Docker 이미지를 빌드합니다.
docker build -t speech-to-text-app .
Docker 구성의 안내에 따라 다음 작업을 실행합니다.
- Docker를 구성합니다.
- 보안 비밀을 만들고
- HaaS에 이미지를 업로드합니다.
사용자 클러스터에 로그인하고 사용자 ID로 kubeconfig 파일을 생성합니다. kubeconfig 경로를 환경 변수로 설정해야 합니다.
export KUBECONFIG=${CLUSTER_KUBECONFIG_PATH}
터미널에서 다음 명령어를 실행하고 API 키를 붙여넣어 Kubernetes 보안 비밀을 만듭니다.
kubectl create secret generic gcp-api-key-secret \ --from-literal=GCP_API_KEY='PASTE_YOUR_API_KEY_HERE'
이 명령어는 키
GCP_API_KEY
이 있는gcp-api-key-secret
이라는 보안 비밀을 만듭니다.Kubernetes 매니페스트를 적용합니다.
apiVersion: batch/v1 kind: Job metadata: name: speech-to-text-test-job spec: template: spec: containers: - name: speech-to-text-test-container image: HARBOR_INSTANCE_URL/HARBOR_PROJECT/speech-to-text-app:latest # Your image path # Mount the API key from the secret into the container # as an environment variable named GCP_API_KEY. imagePullSecrets: - name: SECRET envFrom: - secretRef: name: gcp-api-key-secret restartPolicy: Never backoffLimit: 4
다음을 바꿉니다.
HARBOR_INSTANCE_URL
: Harbor 인스턴스 URL입니다.HARBOR_PROJECT
: Harbor 프로젝트입니다.SECRET
: Docker 사용자 인증 정보를 저장하기 위해 생성된 보안 비밀의 이름입니다.
작업 상태를 확인합니다.
kubectl get jobs/speech-to-text-test-job # It will show 0/1 completions, then 1/1 after it succeeds
작업이 완료되면 포드 로그에서 출력을 볼 수 있습니다.
kubectl logs -l job-name=speech-to-text-test-job