๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Platform/โ˜๏ธ Google Cloud

โ˜๏ธ Google Cloud * ํ…์ŠคํŠธ๋ฅผ ์ฝ์–ด์ฃผ๊ฒ ๋‹ˆ? for Python

Text to Speach๋Š” 2018-06์›” ํ˜„์žฌ Protocol, Java, Node.JS, Python ์œผ๋กœ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ด ํฌ์ŠคํŠธ์—์„œ๋Š” Python์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํฌ์ŠคํŒ… ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์‚ฌ์šฉ ์ˆœ์„œ๋Š” Python ์™ธ์˜ ๋‹ค๋ฅธ ์–ธ์–ด๋„ ๋™์ผํ•˜๊ธฐ์— ์ˆœ์„œ๋งŒ ๋ณด์‹œ๊ณ , Java, Node.JS ๊ฐ™์€ ๊ฒฝ์šฐ ์•„๋ž˜ #์ฐธ์กฐ๋‚ด์šฉ์„ ํ™•์ธํ•˜์„ธ์š”.

 

Google Cloud์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ ˆ์ฐจ๊ฐ€ ๋จผ์ € ์ด๋ฃจ์–ด์ ธ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ‘‰ Before Start Google Cloud Library

 

์‚ฌ์šฉ๋œ Package์˜ variable, method ์ •๋ณด๋ฅผ ์•Œ๊ณ  ์‹ถ์œผ๋ฉด ๋งํฌ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”!

 

 

 


 

 

Text To Speech ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ ์ „

ํ˜น์‹œ๋ผ๋„ Google Cloud๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋ณธ์ธ์ฆ์„ ํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์œ„์˜ Befor Start Google Cloud Library๋ฅผ ๋จผ์ € ๋”ฐ๋ผํ•˜๊ณ  ์™€์ฃผ์„ธ์š”!

 

1. Install the Client library

$ pip install --upgrade google-cloud-texttospeech

 

- - - - ํ™•์ธํ•˜๊ธฐ

 

 

ํ˜น์‹œ ์˜คํƒ€์žˆ์„๊นŒ๋ด ๋ช…๋ น์–ด๋ฅผ ํ•œ ๋ฒˆ ๋” ์ ์–ด๋†“์•˜์Šต๋‹ˆ๋‹ค.

์ œ๋Œ€๋กœ ์ž˜ ์„ค์น˜๊ฐ€ ๋˜๋ฉด ์œ„์™€ ๊ฐ™์ด ์ œ์ผ ๋งˆ์ง€๋ง‰ ์ค„์— Successfully installed google-cloud-texttospeech- ... ์ด๋ผ๊ณ  ๋œน๋‹ˆ๋‹ค.

- - - -

 

2. Environment Setting

$ export GOOGLE_APPLICATION_CREDENTIALS=JSON_ํŒŒ์ผ๊ฒฝ๋กœ

Google Cloud ์‚ฌ์šฉ์„ ์œ„ํ•ด ๋งŒ๋“  JOSN KEY๋ฅผ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋กœ ์„ค์ •ํ•ด์ค๋‹ˆ๋‹ค.

 

 

 

์‚ฌ์šฉํ•ด๋ณด์ž !

1. Code

 

def synthesize_text(text):
    """Synthesizes speech from the input string of text."""
    from google.cloud import texttospeech
    client = texttospeech.TextToSpeechClient()

    input_text = texttospeech.types.SynthesisInput(text=text)

    # Note: the voice can also be specified by name.
    # Names of voices can be retrieved with client.list_voices().
    voice = texttospeech.types.VoiceSelectionParams(
        language_code='en-US',
        ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)

    audio_config = texttospeech.types.AudioConfig(
        audio_encoding=texttospeech.enums.AudioEncoding.MP3)

    response = client.synthesize_speech(input_text, voice, audio_config)

    # The response's audio_content is binary.
    with open('output.mp3', 'wb') as out:
        out.write(response.audio_content)
        print('Audio content written to file "output.mp3"')

 

์ €๋Š” ํ•„์š”ํ•œ ํ•จ์ˆ˜ ์ฝ”๋“œ ๋ถ€๋ถ„๋งŒ ์ ์–ด๋†“์•˜์Šต๋‹ˆ๋‹ค.

์˜ฌ๋ ค๋†“์€ ์ฝ”๋“œ๋Š” ์›๋ณธ ์ฝ”๋“œ๋ฅผ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ์˜จ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํ•„์š”์— ๋”ฐ๋ผ ์ˆ˜์ •ํ•˜๋ฉด ๋˜๊ฒ ์ฃ ?

 

์ €์˜ ๊ฒฝ์šฐ์—๋Š” anguge_code๊ฐ€ ์˜์–ด๋กœ ๋˜์–ด์žˆ์œผ๋‹ˆ ํ•œ๊ตญ์–ด ์‚ฌ์šฉ์„ ์œ„ํ•ด en-US ๋ฅผ ko-KR ๋กœ ์ˆ˜์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

ํŒŒ์ผ๋ช… ๋ถ€๋ถ„๋„ ๋งค๋ฒˆ ๋ฐ”๊พธ์–ด ์ฃผ๊ธฐ ์œ„ํ•˜์—ฌ ๋ณ€์ˆ˜ ํ˜•ํƒœ๋กœ ์ง€์ •ํ•˜์—ฌ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

 

2. Program Start

$ python ์‹คํ–‰ํŒŒ์ผ๋ช…

ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰์‹œ์ผœ์ฃผ์„ธ์š”.

๋™์ž‘์ด ๋๋‚˜๋ฉด ์ง€์ •ํ•œ ํŒŒ์ผ๋ช…์œผ๋กœ voice audio file์ด ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค.

 

 


Thanks for