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

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

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

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

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

1918閲覧

GCP speech to text のエラーについて

s.i1125

総合スコア0

Google API

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

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/09/26 01:03

前提・実現したいこと

GCP speech to textでストリーミング文字起こしをしたい。
ここに質問の内容を詳しく書いてください。
Googleが掲載しているサンプルコードで試したところ、始めは出来たのですが2回以降エラーがでるようになりました。いろいろと調べているのですが、解決策が分かりません。
宜しくお願い致します。

発生している問題・エラーメッセージ

AttributeError Traceback (most recent call last) <ipython-input-5-6e34b0a43110> in <module> 163 164 if __name__ == "__main__": --> 165 main() <ipython-input-5-6e34b0a43110> in main() 139 language_code = "en-US" # a BCP-47 language tag 140 --> 141 client = speech.SpeechClient() 142 config = speech.RecognitionConfig( 143 encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16, AttributeError: module 'google.cloud.speech' has no attribute 'SpeechClient'

該当のソースコード

from future import division

import re
import sys

from google.cloud import speech

import pyaudio
from six.moves import queue

RATE = 16000
CHUNK = int(RATE / 10) # 100ms

class MicrophoneStream(object):
"""Opens a recording stream as a generator yielding the audio chunks."""

def __init__(self, rate, chunk): self._rate = rate self._chunk = chunk self._buff = queue.Queue() self.closed = True def __enter__(self): self._audio_interface = pyaudio.PyAudio() self._audio_stream = self._audio_interface.open( format=pyaudio.paInt16, channels=1, rate=self._rate, input=True, frames_per_buffer=self._chunk, stream_callback=self._fill_buffer, ) self.closed = False return self def __exit__(self, type, value, traceback): self._audio_stream.stop_stream() self._audio_stream.close() self.closed = True self._buff.put(None) self._audio_interface.terminate() def _fill_buffer(self, in_data, frame_count, time_info, status_flags): """Continuously collect data from the audio stream, into the buffer.""" self._buff.put(in_data) return None, pyaudio.paContinue def generator(self): while not self.closed: chunk = self._buff.get() if chunk is None: return data = [chunk] while True: try: chunk = self._buff.get(block=False) if chunk is None: return data.append(chunk) except queue.Empty: break yield b"".join(data)

def listen_print_loop(responses):
"""Iterates through server responses and prints them.

The responses passed is a generator that will block until a response is provided by the server. Each response may contain multiple results, and each result may contain multiple alternatives; for details, see https://goo.gl/tjCPAU. Here we print only the transcription for the top alternative of the top result. In this case, responses are provided for interim results as well. If the response is an interim one, print a line feed at the end of it, to allow the next result to overwrite it, until the response is a final one. For the final one, print a newline to preserve the finalized transcription. """ num_chars_printed = 0 for response in responses: if not response.results: continue result = response.results[0] if not result.alternatives: continue transcript = result.alternatives[0].transcript overwrite_chars = " " * (num_chars_printed - len(transcript)) if not result.is_final: sys.stdout.write(transcript + overwrite_chars + "\r") sys.stdout.flush() num_chars_printed = len(transcript) else: print(transcript + overwrite_chars) if re.search(r"\b(exit|quit)\b", transcript, re.I): print("Exiting..") break num_chars_printed = 0

def main():
language_code = "en-US" # a BCP-47 language tag

client = speech.SpeechClient() config = speech.RecognitionConfig( encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=RATE, language_code=language_code, ) streaming_config = speech.StreamingRecognitionConfig( config=config, interim_results=True ) with MicrophoneStream(RATE, CHUNK) as stream: audio_generator = stream.generator() requests = ( speech.StreamingRecognizeRequest(audio_content=content) for content in audio_generator ) responses = client.streaming_recognize(streaming_config, requests) listen_print_loop(responses)

if name == "main":
main()

ソースコード

試したこと

pip install --upgrade google-cloud-speechでインストールしてるため、verは最新だと思います。

補足情報(FW/ツールのバージョンなど)

python3.8
anaconda→juoyter notebook
windows

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

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

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

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

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

guest

回答1

0

<Speech to Text> <Streamlit>文字起こしアプリのエラーと同様ケースだと思われます。
最新Verではそのモジュールは削除されているようです。

参考:Python クライアント ライブラリ v0.27 への移行

以下のモジュールは、Python Client Library v0.27 パッケージで削除されました。

google.cloud.speech.client

投稿2021/09/28 07:01

can110

総合スコア38266

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

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

s.i1125

2021/09/29 13:25

ご回答ありがとうございます。 解決できました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問