-
[이슈관리] Google Cloud Text-to-Speech(TTS) API, 목소리 성별 바꾸기CS/졸업 프로젝트(Duk to Me) 2023. 6. 26. 05:58반응형
상황
지난번에 설정했던 Google TTS Python 코드에서는 성별이 중성으로 밖에 출력이 안되었다.
# Build the voice request, select the language code ("en-US") and the ssml # voice gender ("neutral") voice = texttospeech.VoiceSelectionParams( language_code="en-US", ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL
위 코드에서 'NEUTRAL'을 아무리 'FEMALE', 'MALE'로 바꾸어도 먹히지 않았다.
해결
공식문서에서 제공하는 이미 정의되어 있는 목소리 설정(https://cloud.google.com/text-to-speech/docs/voices?hl=ko) set 목록을 참고해서 다시 설정하였더니 성별 전환이 원하는대로 가능하였다.
Google TTS에서 제공하는 목소리 목록을 참고하기 위해서 실습에서는 목록들을 출력하는 text file을 만드는 함수를 정의하는 Python 파일을 새로 만들었다.
voices_list.py
from google.cloud import texttospeech from google.oauth2 import service_account # Instantiates a client client_file = 'speech_demo.json' # json 파일명 넣기 credentials = service_account.Credentials.from_service_account_file(client_file) client = texttospeech.TextToSpeechClient(credentials=credentials) def list_voices(): """Lists the available voices.""" # Performs the list voices request voices = client.list_voices() with open("voices_list.txt", "w") as file: for voice in voices.voices: # Write the voice's name to the file file.write(f"Name: {voice.name}\n") # Write the supported language codes for this voice to the file for language_code in voice.language_codes: file.write(f"Supported language: {language_code}\n") ssml_gender = texttospeech.SsmlVoiceGender(voice.ssml_gender) # Write the SSML Voice Gender to the file file.write(f"SSML Voice Gender: {ssml_gender.name}\n") # Write the natural sample rate hertz for this voice to the file file.write(f"Natural Sample Rate Hertz: {voice.natural_sample_rate_hertz}\n\n") # Call the list_voices function list_voices()
위의 코드를 실행했을 때 결과물로 나오는 'voices_list.txt' 파일 목록들을 참고하여 문제가 있던 코드를 수정했다.
# Build the voice request, selecting the desired voice voice = texttospeech.VoiceSelectionParams( language_code="en-US", name="en-US-Standard-A" )
반응형'CS > 졸업 프로젝트(Duk to Me)' 카테고리의 다른 글
Unity에서 여러 Scene으로부터 점수를 합산하여 내는 점수체계 C# Script 코드 쓰기 (0) 2023.08.16 [이슈관리] Unity에서 Google Speech API Asset의 C# Script 고치기 (0) 2023.06.26 Google Cloud Text-to-Speech(TTS) API, Python으로 사용하기 (0) 2023.06.20 Google Cloud Speech-to-Text(STT) API 초기설정및 Python으로 사용하기 (0) 2023.06.20 Google Cloud Speech API 개념및 기능 설명 (0) 2023.06.19