Cookie の設定を選択する

当社は、当社のサイトおよびサービスを提供するために必要な必須 Cookie および類似のツールを使用しています。当社は、パフォーマンス Cookie を使用して匿名の統計情報を収集することで、お客様が当社のサイトをどのように利用しているかを把握し、改善に役立てています。必須 Cookie は無効化できませんが、[カスタマイズ] または [拒否] をクリックしてパフォーマンス Cookie を拒否することはできます。

お客様が同意した場合、AWS および承認された第三者は、Cookie を使用して便利なサイト機能を提供したり、お客様の選択を記憶したり、関連する広告を含む関連コンテンツを表示したりします。すべての必須ではない Cookie を受け入れるか拒否するには、[受け入れる] または [拒否] をクリックしてください。より詳細な選択を行うには、[カスタマイズ] をクリックしてください。

SDK for Ruby を使用した Amazon Polly の例 - AWS SDK コード例

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

SDK for Ruby を使用した Amazon Polly の例

次のコード例は、Amazon Polly AWS SDK for Ruby で を使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。

アクションはより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

「シナリオ」は、1 つのサービス内から、または他の AWS のサービスと組み合わせて複数の関数を呼び出し、特定のタスクを実行する方法を示すコード例です。

各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。

アクション

次のコード例は、DescribeVoices を使用する方法を示しています。

SDK for Ruby
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

require 'aws-sdk-polly' # In v2: require 'aws-sdk' begin # Create an Amazon Polly client using # credentials from the shared credentials file ~/.aws/credentials # and the configuration (region) from the shared configuration file ~/.aws/config polly = Aws::Polly::Client.new # Get US English voices resp = polly.describe_voices(language_code: 'en-US') resp.voices.each do |v| puts v.name puts " #{v.gender}" puts end rescue StandardError => e puts 'Could not get voices' puts 'Error message:' puts e.message end
  • API の詳細については、AWS SDK for Ruby API リファレンスの「DescribeVoices」を参照してください。

次のコード例は、DescribeVoices を使用する方法を示しています。

SDK for Ruby
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

require 'aws-sdk-polly' # In v2: require 'aws-sdk' begin # Create an Amazon Polly client using # credentials from the shared credentials file ~/.aws/credentials # and the configuration (region) from the shared configuration file ~/.aws/config polly = Aws::Polly::Client.new # Get US English voices resp = polly.describe_voices(language_code: 'en-US') resp.voices.each do |v| puts v.name puts " #{v.gender}" puts end rescue StandardError => e puts 'Could not get voices' puts 'Error message:' puts e.message end
  • API の詳細については、AWS SDK for Ruby API リファレンスの「DescribeVoices」を参照してください。

次の例は、ListLexicons を使用する方法を説明しています。

SDK for Ruby
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

require 'aws-sdk-polly' # In v2: require 'aws-sdk' begin # Create an Amazon Polly client using # credentials from the shared credentials file ~/.aws/credentials # and the configuration (region) from the shared configuration file ~/.aws/config polly = Aws::Polly::Client.new resp = polly.list_lexicons resp.lexicons.each do |l| puts l.name puts " Alphabet:#{l.attributes.alphabet}" puts " Language:#{l.attributes.language}" puts end rescue StandardError => e puts 'Could not get lexicons' puts 'Error message:' puts e.message end
  • API の詳細については、AWS SDK for Ruby API リファレンスの「ListLexicons」を参照してください。

次の例は、ListLexicons を使用する方法を説明しています。

SDK for Ruby
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

require 'aws-sdk-polly' # In v2: require 'aws-sdk' begin # Create an Amazon Polly client using # credentials from the shared credentials file ~/.aws/credentials # and the configuration (region) from the shared configuration file ~/.aws/config polly = Aws::Polly::Client.new resp = polly.list_lexicons resp.lexicons.each do |l| puts l.name puts " Alphabet:#{l.attributes.alphabet}" puts " Language:#{l.attributes.language}" puts end rescue StandardError => e puts 'Could not get lexicons' puts 'Error message:' puts e.message end
  • API の詳細については、AWS SDK for Ruby API リファレンスの「ListLexicons」を参照してください。

次のコード例は、SynthesizeSpeech を使用する方法を示しています。

SDK for Ruby
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

require 'aws-sdk-polly' # In v2: require 'aws-sdk' begin # Get the filename from the command line if ARGV.empty? puts 'You must supply a filename' exit 1 end filename = ARGV[0] # Open file and get the contents as a string if File.exist?(filename) contents = IO.read(filename) else puts "No such file: #{filename}" exit 1 end # Create an Amazon Polly client using # credentials from the shared credentials file ~/.aws/credentials # and the configuration (region) from the shared configuration file ~/.aws/config polly = Aws::Polly::Client.new resp = polly.synthesize_speech({ output_format: 'mp3', text: contents, voice_id: 'Joanna' }) # Save output # Get just the file name # abc/xyz.txt -> xyx.txt name = File.basename(filename) # Split up name so we get just the xyz part parts = name.split('.') first_part = parts[0] mp3_file = "#{first_part}.mp3" IO.copy_stream(resp.audio_stream, mp3_file) puts "Wrote MP3 content to: #{mp3_file}" rescue StandardError => e puts 'Got error:' puts 'Error message:' puts e.message end
  • API の詳細については、「AWS SDK for Ruby API リファレンス」の「SynthesizeSpeech」を参照してください。

次のコード例は、SynthesizeSpeech を使用する方法を示しています。

SDK for Ruby
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

require 'aws-sdk-polly' # In v2: require 'aws-sdk' begin # Get the filename from the command line if ARGV.empty? puts 'You must supply a filename' exit 1 end filename = ARGV[0] # Open file and get the contents as a string if File.exist?(filename) contents = IO.read(filename) else puts "No such file: #{filename}" exit 1 end # Create an Amazon Polly client using # credentials from the shared credentials file ~/.aws/credentials # and the configuration (region) from the shared configuration file ~/.aws/config polly = Aws::Polly::Client.new resp = polly.synthesize_speech({ output_format: 'mp3', text: contents, voice_id: 'Joanna' }) # Save output # Get just the file name # abc/xyz.txt -> xyx.txt name = File.basename(filename) # Split up name so we get just the xyz part parts = name.split('.') first_part = parts[0] mp3_file = "#{first_part}.mp3" IO.copy_stream(resp.audio_stream, mp3_file) puts "Wrote MP3 content to: #{mp3_file}" rescue StandardError => e puts 'Got error:' puts 'Error message:' puts e.message end
  • API の詳細については、「AWS SDK for Ruby API リファレンス」の「SynthesizeSpeech」を参照してください。

シナリオ

次のコード例は、顧客のコメントカードを分析し、元の言語から翻訳し、顧客の感情を判断し、翻訳されたテキストから音声ファイルを生成するアプリケーションの作成方法を示しています。

SDK for Ruby

このサンプルアプリケーションは、顧客フィードバックカードを分析し、保存します。具体的には、ニューヨーク市の架空のホテルのニーズを満たします。このホテルでは、お客様からのフィードバックをさまざまな言語で書かれた実際のコメントカードの形で受け取ります。そのフィードバックは、ウェブクライアントを通じてアプリにアップロードされます。コメントカードの画像をアップロードされると、次の手順が発生します。

  • テキストは Amazon Textract を使用して、画像から抽出されます。

  • Amazon Comprehend は、抽出されたテキストの感情とその言語を決定します。

  • 抽出されたテキストは、Amazon Translate を使用して英語に翻訳されます。

  • Amazon Polly は抽出されたテキストからオーディオファイルを合成します。

完全なアプリは  AWS CDK を使用してデプロイすることができます。ソースコードとデプロイ手順については、GitHub のプロジェクトを参照してください。

この例で使用されているサービス
  • Amazon Comprehend

  • Lambda

  • Amazon Polly

  • Amazon Textract

  • Amazon Translate

次のコード例は、顧客のコメントカードを分析し、元の言語から翻訳し、顧客の感情を判断し、翻訳されたテキストから音声ファイルを生成するアプリケーションの作成方法を示しています。

SDK for Ruby

このサンプルアプリケーションは、顧客フィードバックカードを分析し、保存します。具体的には、ニューヨーク市の架空のホテルのニーズを満たします。このホテルでは、お客様からのフィードバックをさまざまな言語で書かれた実際のコメントカードの形で受け取ります。そのフィードバックは、ウェブクライアントを通じてアプリにアップロードされます。コメントカードの画像をアップロードされると、次の手順が発生します。

  • テキストは Amazon Textract を使用して、画像から抽出されます。

  • Amazon Comprehend は、抽出されたテキストの感情とその言語を決定します。

  • 抽出されたテキストは、Amazon Translate を使用して英語に翻訳されます。

  • Amazon Polly は抽出されたテキストからオーディオファイルを合成します。

完全なアプリは  AWS CDK を使用してデプロイすることができます。ソースコードとデプロイ手順については、GitHub のプロジェクトを参照してください。

この例で使用されているサービス
  • Amazon Comprehend

  • Lambda

  • Amazon Polly

  • Amazon Textract

  • Amazon Translate

プライバシーサイト規約Cookie の設定
© 2025, Amazon Web Services, Inc. or its affiliates.All rights reserved.