質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

0回答

2865閲覧

Google Speech APIでの時間付き出力の方法

kohhi

総合スコア18

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

1クリップ

投稿2017/04/03 10:10

編集2017/04/04 10:07

###前提・実現したいこと
Google Speech API を使って、音声のテキスト出力を行っているのですが、
出力に、各単語が音声ファイル内のどの時間に発話されたものであるかを知りたいのですが、どのように行えばいいかわかりません、お詳しい方宜しくお願いします。

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/cloud-client/transcribe_async.py

上記のコードにマイナーチェンジを行ったもので出力を行っています。ここにどのようにコードを足せば、時間つきのファイルになるのかを知りたいです
###該当のソースコード
#!/usr/bin/env python

  • Copyright 2017 Google Inc. All Rights Reserved.-
  • Licensed under the Apache License, Version 2.0 (the "License");-
  • you may not use this file except in compliance with the License.-
  • You may obtain a copy of the License at-
  • http://www.apache.org/licenses/LICENSE-2.0-

--

  • Unless required by applicable law or agreed to in writing, software-
  • distributed under the License is distributed on an "AS IS" BASIS,-
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.-
  • See the License for the specific language governing permissions and-
  • limitations under the License.-

---Google Cloud Speech API sample application using the REST API for async
batch processing.

Example usage:
python transcribe_async.py resources/audio.raw
python transcribe_async.py gs://cloud-samples-tests/speech/brooklyn.flac

import argparse
import io
import time

def transcribe_file(speech_file):
---Transcribe the given audio file asynchronously.---
from google.cloud import speech
speech_client = speech.Client()

with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() audio_sample = speech_client.sample( content, source_uri=None, encoding='FLAC', sample_rate=16000) operation = speech_client.speech_api.async_recognize(audio_sample, language_code='en-GB', speech_context=['<登録した単語>'], retry_count = 100 while retry_count > 0 and not operation.complete: retry_count -= 1 time.sleep(2) operation.poll() if not operation.complete: print('Operation not complete and retry limit reached.') return alternatives = operation.results for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) print('Confidence: {}'.format(alternative.confidence)) - [END send_request] -

def transcribe_gcs(gcs_uri):
---Asynchronously transcribes the audio file specified by the gcs_uri.---
from google.cloud import speech
speech_client = speech.Client()

audio_sample = speech_client.sample( content=None, source_uri=gcs_uri, encoding='FLAC', sample_rate=16000) operation = speech_client.speech_api.async_recognize(audio_sample) retry_count = 100 while retry_count > 0 and not operation.complete: retry_count -= 1 time.sleep(2) operation.poll() if not operation.complete: print('Operation not complete and retry limit reached.') return alternatives = operation.results for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) print('Confidence: {}'.format(alternative.confidence)) -[END send_request_gcs]-

if name == 'main':
parser = argparse.ArgumentParser(
description=doc,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
'path', help='File or GCS path for audio file to be recognized')
args = parser.parse_args()
if args.path.startswith('gs://'):
transcribe_gcs(args.path)
else:
transcribe_file(args.path)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

can110

2017/04/03 15:37

「マイナーチェンジ」したソースを提示ください。
kohhi

2017/04/04 10:07

ソース提示致しました。宜しくお願い致します。
can110

2017/04/04 14:04

ソース中に「各単語」を識別する情報(処理)がないようですが、どの部分か明示ください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問