LoginSignup
1
1

More than 3 years have passed since last update.

google speech apiの音声変換で使う音声ファイル

Posted at

映像(mp4)をmp3に変換し、wavに変換します。
wavに変換します。
wavに変換するときは、monoオーディオに変換することと、サンプルレートを忘れないようにしておく必要があります。

Audio Auditionでmp3からwavに変換しました。

変換する際の設定は以下のようにしました。

image.png

import io
import os

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

# Instantiates a client
client = speech.SpeechClient()

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


with io.open(file_name, 'rb') as audio_file:
    content = audio_file.read()
    audio = types.RecognitionAudio(content=content)

config = types.RecognitionConfig(
    encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=16000, # サンプルレート
    language_code='ja-JP') # 日本語指定

response = client.recognize(config, audio)

for result in response.results:
    print('Transcript: {}'.format(result.alternatives[0].transcript))

コンソールに日本語が表示されました!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1