이 페이지에서는 REST 인터페이스와 curl 명령어를 사용하여 Speech-to-Text에 음성 인식 요청을 보내는 방법을 설명합니다.
Speech-to-Text를 사용하면 Google 음성 인식 기술을 개발자 애플리케이션에 간편하게 통합할 수 있습니다. 오디오 데이터를 Speech-to-Text API로 보내면 Speech-to-Text API가 해당 오디오 파일의 텍스트 스크립트를 반환합니다. 이 서비스에 대한 자세한 내용은 Speech-to-Text 기본사항을 참조하세요.
시작하기 전에
Speech-to-Text API에 요청을 보내려면 먼저 다음 작업을 완료해야 합니다. 자세한 내용은 시작하기 전에 페이지를 참조하세요.
GCP 프로젝트에서 Speech-to-Text를 사용 설정합니다.
Speech-to-Text에 결제가 사용 설정되어 있는지 확인합니다.
Install the Google Cloud CLI.
After installation,
initialize the Google Cloud CLI by running the following command:
이 JSON 스니펫은 오디오 파일이 FLAC 인코딩 형식이고, 샘플링 레이트가 16000Hz이며, 오디오 파일이 주어진 URI의 Google Cloud Storage에 저장되어 있음을 나타냅니다. 오디오 파일은 공개적으로 액세스될 수 있으므로, 파일에 액세스하기 위해 사용자 인증 정보를 인증할 필요가 없습니다.
curl을 사용하여 speech:recognize 요청을 실행합니다. 이때 1단계에서 설정한 JSON 요청의 파일 이름을 전달합니다.
샘플 curl 명령어는 gcloud auth print-access-token 명령어를 사용하여 인증 토큰을 가져옵니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Quickstart: Transcribe speech to text by using the API\n\nTranscribe speech to text by using the API\n==========================================\n\nThis page shows you how to send a speech recognition request to\nSpeech-to-Text using the [REST interface](/speech-to-text/docs/reference/rest)\nand the `curl` command.\n\n\nSpeech-to-Text enables easy integration of Google speech\nrecognition technologies into developer applications. You can send\naudio data to the Speech-to-Text API, which then returns a\ntext transcription of that audio file. For more information about\nthe service, see\n[Speech-to-Text basics](/speech-to-text/docs/basics).\n\n\nBefore you begin\n----------------\n\nBefore you can send a request to the Speech-to-Text API, you must have completed\nthe following actions. See the\n[before you begin](/speech-to-text/docs/before-you-begin) page for details.\n\n- Enable Speech-to-Text on a GCP project.\n 1. Make sure billing is enabled for Speech-to-Text.\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n- (Optional) Create a new Google Cloud Storage bucket to store your audio data.\n\nMake an audio transcription request\n-----------------------------------\n\nNow you can use Speech-to-Text to transcribe an audio file\nto text. Use the following code sample to send a\n[`recognize`](/speech-to-text/docs/reference/rest/v1/speech/recognize) REST request to the Speech-to-Text API.\n\n1. Create a JSON request file with the following text, and save it as a\n `sync-request.json` plain text file:\n\n ```json\n {\n \"config\": {\n \"encoding\":\"FLAC\",\n \"sampleRateHertz\": 16000,\n \"languageCode\": \"en-US\",\n \"enableWordTimeOffsets\": false\n },\n \"audio\": {\n \"uri\":\"gs://cloud-samples-tests/speech/brooklyn.flac\"\n }\n }\n \n ```\n\n This JSON snippet indicates that the audio file has a FLAC encoding format,\n a sample rate of 16000 Hz, and that the audio file is stored on Google Cloud\n Storage at the given URI. The audio file is publicly accessible, so you\n don't need authentication credentials to access the file.\n2. Use `curl` to make a `speech:recognize`\n request, passing it the filename of the JSON request you set up in step 1:\n\n The sample `curl` command uses the `gcloud auth print-access-token` command to get an authentication token. \n\n ```sh\n curl -s -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer \"$(gcloud auth print-access-token) \\\n https://speech.googleapis.com/v1/speech:recognize \\\n -d @sync-request.json\n \n ```\n\n Note that to pass a filename to `curl` you use the\n `-d` option (for \"data\") and precede the filename with an\n `@` sign. This file should be in the same directory in which you\n execute the `curl` command.\n\n You should see a response similar to the following: \n\n ```json\n {\n \"results\": [\n {\n \"alternatives\": [\n {\n \"transcript\": \"how old is the Brooklyn Bridge\",\n \"confidence\": 0.98267895\n }\n ]\n }\n ]\n }\n \n ```\n\nCongratulations! You've sent your first request to Speech-to-Text.\n\n\nIf you receive an error or an empty response from\nSpeech-to-Text, take a look at the\n[troubleshooting](/speech-to-text/docs/troubleshooting) and\n[error mitigation](/speech-to-text/docs/error-messages) steps.\n\nClean up\n--------\n\n\nTo avoid incurring charges to your Google Cloud account for\nthe resources used on this page, follow these steps.\n\n- Use the [Google Cloud console](https://console.cloud.google.com/) to delete your project if you do not need it.\n\nWhat's next\n-----------\n\n\n- Practice [transcribing short audio files](/speech-to-text/docs/sync-recognize).\n- Learn how to [batch long audio files for speech recognition](/speech-to-text/docs/async-recognize).\n- Learn how to [transcribe streaming audio](/speech-to-text/docs/streaming-recognize) like from a microphone.\n- Get started with the Speech-to-Text in your language of choice by using a [Speech-to-Text client library](/speech-to-text/docs/reference/libraries).\n- Work through the [sample applications](/speech-to-text/docs/samples).\n- For best performance, accuracy, and other tips, see the [best practices](/speech-to-text/docs/best-practices) documentation.\n\n\u003cbr /\u003e"]]