[Google Study JAM] Speech to Text Transcription with the Cloud Speech API
👨🏻‍🏫IT 활동/Google Study JAM

[Google Study JAM] Speech to Text Transcription with the Cloud Speech API

728x90
반응형

Speech to Text Transcription with the Cloud Speech API



이번에도 Speech ( audio file )을 Text형태로 나타내주는 API를 이용한다.

추가적으로 multilingually 하게 Text 형태로 변환시킨다. 



1. 이전과 마찬가지로 GCP에 접속하여 Cloud Shell을 활성화 시킨다. 


2. Credential API KEY를 받고, 경로설정을 해준다. 



export API_KEY=<YOUR_API_KEY>




3. Create your Speech API request


touch request.json



 request.json 파일을 먼저 만들고 아래의 내용을 Nano를 통해 수정한다.


{ "config": { "encoding":"FLAC", "languageCode": "en-US" }, "audio": { "uri":"gs://cloud-samples-tests/speech/brooklyn.flac" } }



크게 Config / audio로 나뉘어져있다. 

Config를 통해 Speech API를 이용해 request에 어떻게 접근할지를 설정한다. 

audio는 음성 파일을 불러오는 역할을 한다.


4-1. Call the Speech API (English)



앞서 만든 request.json을 이용해 Speech API를 이용해 보는 과정이다. 


curl -s -X POST -H "Content-Type: application/json" --data-binary @request.json \ "https://speech.googleapis.com/v1/speech:recognize?key=${API_KEY}"


결과는 다음과 같다.


{ "results": [ { "alternatives": [ { "transcript": "how old is the Brooklyn Bridge", "confidence": 0.98267895 } ] } ] }



transcript 는 Text로 변환된 audio 파일을 나타낸다. confidence는 그 정확도를 말한다.



4-2. Call the Speech API (French)


다시 request.json 파일로 돌아가서 아래와 같이 수정을 해준다.



{ "config": { "encoding":"FLAC", "languageCode": "fr" }, "audio": { "uri":"gs://speech-language-samples/fr-sample.flac" } }


language가 "fr" 프랑스어로 바뀌었고, 이에 맞는 audio 파일로 바뀌었다. 


{ "results": [ { "alternatives": [ { "transcript": "maître corbeau sur un arbre perché tenait en son bec un fromage", "confidence": 0.9710122 } ] } ] }



결과는 위와 같다. 

English로 했을 때와 마찬가지로, Speech가 Text로 나온 transcript와 정확도인 confidence를 볼 수 있다.



이번에는 영어 뿐만아니라 다른 언어들의 Speech를 Text로 변환하는 API를 경험했다. 


728x90
반응형