이 페이지에서는 REST 인터페이스와 curl 명령어를 사용하여 Speech-to-Text에 음성 인식 요청을 보내는 방법을 설명합니다.
Speech-to-Text를 사용하면 Google 음성 인식 기술을 개발자 애플리케이션에 간편하게 통합할 수 있습니다. 오디오 데이터를 Speech-to-Text API로 보내면 Speech-to-Text API가 해당 오디오 파일의 텍스트 스크립트를 반환합니다. 서비스에 대한 자세한 내용은 Cloud STT 기본사항을 참고하세요.
시작하기 전에
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Speech-to-Text APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
Make sure that you have the following role or roles on the project: Cloud Speech Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
IAM으로 이동 - 프로젝트를 선택합니다.
- 액세스 권한 부여를 클릭합니다.
-
새 주 구성원 필드에 사용자 식별자를 입력합니다. 일반적으로 직원 ID 풀의 사용자 식별자입니다. 자세한 내용은 IAM 정책에서 직원 풀 사용자 표현을 참고하거나 관리자에게 문의하세요.
- 역할 선택 목록에서 역할을 선택합니다.
- 역할을 추가로 부여하려면 다른 역할 추가를 클릭하고 각 역할을 추가합니다.
- 저장을 클릭합니다.
Install the Google Cloud CLI.
gcloud CLI에서 제휴 ID를 사용하도록 구성합니다.
자세한 내용은 제휴 ID로 gcloud CLI에 로그인을 참고하세요.
gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다.
gcloud init오디오 텍스트 변환 요청하기
다음 코드 샘플을 사용하여 Speech-to-Text API에
recognizeREST 요청을 보냅니다.이 명령어를 실행하여 요청에 대한 입력으로 JSON 파일을 만듭니다.
/full/path/to/audio/file.wav를 텍스트 변환을 수행할 오디오 파일의 경로로 바꿉니다.echo "{ \"config\": { \"auto_decoding_config\": {}, \"language_codes\": [\"en-US\"], \"model\": \"long\" }, \"content\": \"$(base64 -w 0 /full/path/to/audio/file.wav | sed 's/+/-/g; s/\//_/g')\" }" > /tmp/data.txtcurl을 사용하여recognize요청을 수행합니다.curl -X POST -H "Content-Type: application/json; charset=utf-8" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -d @/tmp/data.txt \ https://speech.googleapis.com/v2/projects/PROJECT_ID/locations/global/recognizers/_:recognize다음과 비슷한 응답이 표시됩니다.
{ "results": [ { "alternatives": [ { "transcript": "how old is the Brooklyn Bridge", "confidence": 0.98267895 } ] } ] }
첫 번째 요청을 Speech-to-Text에 보냈습니다.
삭제
이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 다음 단계를 수행합니다.
-
Optional: Revoke the authentication credentials that you created, and delete the local credential file.
gcloud auth application-default revoke
-
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke
콘솔
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
gcloud
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
다음 단계
- 클라이언트 라이브러리를 사용하여 선호하는 프로그래밍 언어로 오디오 스크립트 작성
- 짧은 오디오 파일의 텍스트 변환 방법 알아보기
- 스트리밍 오디오의 텍스트 변환 방법 알아보기
- 긴 오디오 파일의 텍스트 변환 방법 알아보기
- 권장사항 문서에서 최상의 성능, 정확도, 기타 팁 참조하기
-