במדריך הזה מוסבר איך להריץ בדיקה של המרת דיבור לטקסט באמצעות שירות הדיבור של Vertex AI מבית Google.
לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python במאמר התחלה מהירה של Vertex AI באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של ה-API בשפת Python של Vertex AI.
יוצרים קובץ Python
speech-to-text-test.py. מחליפים את הערך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" (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"]יוצרים את קובץ האימג' של Docker לאפליקציית Speech-to-Text:
docker build -t speech-to-text-app .פועלים לפי ההוראות במאמר הגדרת Docker כדי:
- מגדירים את Docker,
- יוצרים סוד, ו
- מעלים את התמונה ל-HaaS.
נכנסים לאשכול המשתמשים ויוצרים את קובץ ה-kubeconfig שלו עם זהות משתמש. חשוב לוודא שהגדרתם את הנתיב של kubeconfig כמשתנה סביבה:
export KUBECONFIG=${CLUSTER_KUBECONFIG_PATH}כדי ליצור סוד של Kubernetes, מריצים את הפקודה הבאה בטרמינל ומדביקים את מפתח ה-API:
kubectl create secret generic gcp-api-key-secret \ --from-literal=GCP_API_KEY='PASTE_YOUR_API_KEY_HERE'הפקודה הזו יוצרת סוד בשם
gcp-api-key-secretעם מפתחGCP_API_KEY.החלת מניפסט 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: כתובת ה-URL של מופע Harbor. -
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אחרי שהעבודה מסתיימת, אפשר לראות את הפלט ביומני ה-pod:
kubectl logs -l job-name=speech-to-text-test-job