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

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

新規登録して質問してみよう
ただいま回答率
85.50%
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

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

Q&A

解決済

1回答

864閲覧

google cloud sdk (python)で texttospeech の gender が見つかりませんと言われる

Shoto9023

総合スコア9

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

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

0グッド

0クリップ

投稿2022/01/02 22:27

編集2022/01/03 09:52

Google Cloud SDKを使用してText-To-Speech APIを呼びだすスクリプトを書いたのですが、以前のサーバー環境で動いていたものを移植したところエラーを吐かれるようになってしまいました

AttributeError: module 'google.cloud.texttospeech' has no attribute 'SsmlVoiceGender'

ソース

py

1from os import name 2import os 3import sys 4from discord.enums import SpeakingState 5sys.path.append('/root/google-cloud-sdk/bin/') 6import discord 7import info 8import func 9import re 10import random 11import datetime 12import html 13import time 14from discord.channel import VoiceChannel 15from discord.player import FFmpegPCMAudio 16from google.cloud import texttospeech 17from collections import defaultdict, deque 18 19... 20 21voiceChannel: VoiceChannel 22speechChannel: discord.channel 23connected: bool 24spQueue: str 25namemode: bool 26isalnum: bool 27queue_dict = defaultdict(deque) 28 29... 30 31 elif connected and message.channel == speechChannel: 32 if message.author.bot: 33 return 34 else: 35 if namemode==0: 36 make_voice(voiceChannel, message.content, '', message.guild) 37 elif namemode==1: 38 if message.author.nick: 39 nick = message.author.nick 40 else: 41 nick = message.author.name 42 make_voice(voiceChannel, message.content, nick, message.guild) 43 elif namemode==2: 44 make_voice(voiceChannel, message.content, message.author.name, message.guild) 45 46def text_to_ssml(text, author): 47 global isalnum 48 escaped_lines = html.escape(text) 49 spacing = " " 50 hyperlink = " Insersion of Hyper link " 51 isalnum = True 52 p = re.compile('[a-zA-Z0-9!?. ]+') 53 if escaped_lines == "": 54 spacing="" 55 elif not p.fullmatch(escaped_lines): 56 spacing = "。" 57 hyperlink = "ハイパーリンク" 58 isalnum = False 59 ssml = "{}".format( 60 re.sub(' ',spacing,(re.sub('[0-9]{14,}','',(re.sub('http[a-zA-Z_0-9./:?]{4,}',hyperlink,escaped_lines))))).replace('<:','').replace(':>','')+spacing+author 61 ) 62 return ssml 63 64def ssml_to_speech(ssml, file, language_code, gender): 65 ttsClient = texttospeech.TextToSpeechClient() 66 synthesis_input = texttospeech.SynthesisInput(text=ssml) 67 voice = texttospeech.VoiceSelectionParams( 68 language_code=language_code, ssml_gender=gender 69 ) 70 audio_config = texttospeech.AudioConfig( 71 audio_encoding=texttospeech.AudioEncoding.MP3 72 ) 73 response = ttsClient.synthesize_speech( 74 input=synthesis_input, voice=voice, audio_config=audio_config 75 ) 76 with open(file,"wb") as out: 77 out.write(response.audio_content) 78 return file 79 80def make_voice(voiceClient, text, author, guild): 81 ssml = text_to_ssml(text, author) 82 filename = time.time() 83 if isalnum: 84 file = ssml_to_speech(ssml, f"{filename}.mp3", "en-US", texttospeech.SsmlVoiceGender.FEMALE) 85 print("Text Chat Reading in en-US ->"+ssml) 86 else: 87 file = ssml_to_speech(ssml, f"{filename}.mp3", "ja-JP", texttospeech.SsmlVoiceGender.FEMALE) 88 print("Text Chat Reading in ja-JP ->"+ssml) 89 enqueue(voiceClient, guild, file) 90 91def enqueue(voiceClient, guild, source): 92 queue = queue_dict[guild.id] 93 queue.append(source) 94 if not voiceClient.is_playing(): 95 play(voiceClient, queue) 96 97def play(voiceClient, queue): 98 if not queue or voiceClient.is_playing(): 99 return 100 source = queue.popleft() 101 voiceClient.play(FFmpegPCMAudio(source, options="-loglevel panic"), after=lambda e:play(voiceClient, queue)) 102 time.sleep(1) 103 os.remove(source)

今までのサーバー上では正常に動作していたので多分ライブラリのインストール状況が原因だとは思うのですが、私では切り分けや特定ができないので質問させていただきました。

サーバー環境は

OSUbuntu 20.04.3 LTS : GNU/Linux 5.11.0-43-generic x86_64Ubuntu 20.04.3 LTS : GNU/Linux 5.8.0-49-generic x86_64
仮想CPU6コア2コア
仮想メモリ6GB2GB
ストレージ50GB SSD25GB SSD
Python バージョンPython 3.8.10Python 3.8.10
gcloud バージョン367.0.0367.0.0

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

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

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

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

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

Supernove

2022/01/03 04:10

今までどういうサーバーの環境で動かしていたのかと、移植先のサーバー環境を教えてもらってもいいでしょうか? 実行環境が変わっているということはまずはそこから考えられそうな原因があるかもしれません
Shoto9023

2022/01/03 09:53

サーバー環境について、追記しました
guest

回答1

0

自己解決

pip listを両方のサーバーで行ったところ、新しいほうのサーバーの方がなぜかバージョンの古いパッケージがインストールされていたようで、pip uninstall google-cloud-texttospeechしてからpip install google-cloud-texttospeechしたら解決しました
大変失礼しました

投稿2022/01/05 04:58

Shoto9023

総合スコア9

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問