파이썬 구글 클라우드 스피치 연동

Jay
5 min readJun 18, 2019

--

클라우드 스피치

위에 접속 후

Speak it!

준비사항

1. 이용가격

20190619기준

웨이브넷 이용시 : 1000000/16$(2000원) 약 500자/원

2. 프로젝트를 생성

바로 나오지 않고 한 5분정도 기다리니 생성이 된다

3. 결제설정

여기서 설정하면된다

4. API사용설정

5. 인증설정

6. 환경 변수 추가

이렇게 해도되고

아니면 아래 코드를 포함시켜준다

import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/path/to/file.json"

7. Cloud SDK 설치 및 초기화

그냥 쭉 Next만 누름

1. 패키지인스톨

pip install --upgrade google-cloud-texttospeech

2. 샘플코드

import osos.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/path/to/file.json"from google.cloud import texttospeechclient = texttospeech.TextToSpeechClient()
input = texttospeech.types.SynthesisInput(text="Hello, World!")
voice = texttospeech.types.VoiceSelectionParams(
language_code='en-US',
ssml_gender=texttospeech.enums.SsmlVoiceGender.NEUTRAL)
audio_config = texttospeech.types.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding.MP3)
response = client.synthesize_speech(input, voice, audio_config)with open('output.mp3', 'wb') as out:
# Write the response to the output file.
out.write(response.audio_content)
print('Audio content written to file "output.mp3"')

--

--

Jay
Jay

Written by Jay

Brain Neural Network : Where neuroscience meets machine learning

No responses yet