前提・実現したいこと
Speech-to-TextとStreamlitを利用した文字起こしアプリを作成しています。
文字起こしを開始すると以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
エラーメッセージ
AttributeError: module 'google.cloud.speech' has no attribute 'SpeechClient'
File "***script_runner.py", line 333, in _run_script
exec(code, module.dict)
File "**.py", line 52, in <module>
transcribe_file(content, lang=option)
File "**", line 16, in transcribe_file
client = speech.SpeechClient()
該当のソースコード
Python
import os from google.cloud import speech import streamlit as st os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'secret.json' def transcribe_file(speech_file, lang='日本語'): lang_code = { '英語': 'en-US', '日本語': 'ja-JP', 'スペイン語': 'es-ES' } ** client = speech.SpeechClient()** ←エラー箇所 audio = speech.RecognitionAudio(content=content) config = speech.RecognitionConfig( encoding=speech.RecognitionConfig.AudioEncoding.ENCODING_UNSPECIFIED, language_code=lang_code[lang] ) response = client.recognize(config=config, audio=audio) for result in response.results: st.write(result.alternatives[0].transcript) st.title('~') st.header('概要') st.write('~') st.markdown('~', unsafe_allow_html=True) upload_file=st.file_uploader('ファイルのアップロード', type=['mp3', 'wav']) if upload_file is not None: content = upload_file.read() st.subheader('ファイル詳細') file_details = {'FileName': upload_file.name, 'FileType': upload_file.type, 'FileSize': upload_file.size} st.write(file_details) st.subheader('音声の再生') st.audio(content) st.subheader('言語選択') option = st.selectbox('翻訳言語を選択してください', ('英語', '日本語', 'スペイン語')) st.write('選択中の言語:' ,option) st.write('文字起こし') if st.button('開始'): comment = st.empty() comment.write('文字起こしを開始します') **transcribe_file(content, lang=option)** ←エラー箇所 comment.write('完了しました')
まだ回答がついていません
会員登録して回答してみよう