2017-04-04 42 views
1

我想了解Google语音文本API。我尝试了谷歌云提供的示例代码API如何在Google Speech API中设置语言Python客户端

这是我的代码:

import io 
import os 

# Imports the Google Cloud client library 
from google.cloud import speech 

# Instantiates a client 
speech_client = speech.Client() 

# The name of the audio file to transcribe 
file_name = os.path.join(
    os.path.dirname(__file__), 
    'resources', 
    'audio.raw') 

# Loads the audio into memory 
with io.open(file_name, 'rb') as audio_file: 
    content = audio_file.read() 
    audio_sample = speech_client.sample(
     content, 
     source_uri=None, 
     encoding='LINEAR16', 
     sample_rate=16000) 

# Detects speech in the audio file 
alternatives = speech_client.speech_api.sync_recognize(audio_sample) 

for alternative in alternatives: 
    print('Transcript: {}'.format(alternative.transcript)) 

然后,我想知道我如何可以使用,而不是英语之外的语言。 有一件事我想用韩文识别,而不是英文。 那么,请问,我应该如何将这段代码放入韩文识别中? ko-kr是Google提供的语言代码。

回答

相关问题