Amazon Polly examples using SDK for SAP ABAP - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Amazon Polly examples using SDK for SAP ABAP

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for SAP ABAP with Amazon Polly.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use DeleteLexicon.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_ply->deletelexicon( iv_name ). MESSAGE 'Lexicon deleted successfully.' TYPE 'I'. CATCH /aws1/cx_plylexiconnotfoundex. MESSAGE 'Lexicon not found.' TYPE 'E'. CATCH /aws1/cx_plyservicefailureex. MESSAGE 'Service failure occurred.' TYPE 'E'. ENDTRY.
  • For API details, see DeleteLexicon in AWS SDK for SAP ABAP API reference.

The following code example shows how to use DescribeVoices.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. " Only pass optional parameters if they have values IF iv_engine IS NOT INITIAL AND iv_language IS NOT INITIAL. oo_result = lo_ply->describevoices( iv_engine = iv_engine iv_languagecode = iv_language ). ELSEIF iv_engine IS NOT INITIAL. oo_result = lo_ply->describevoices( iv_engine = iv_engine ). ELSEIF iv_language IS NOT INITIAL. oo_result = lo_ply->describevoices( iv_languagecode = iv_language ). ELSE. oo_result = lo_ply->describevoices( ). ENDIF. MESSAGE 'Retrieved voice metadata.' TYPE 'I'. CATCH /aws1/cx_plyinvalidnexttokenex. MESSAGE 'The NextToken is invalid.' TYPE 'E'. CATCH /aws1/cx_plyservicefailureex. MESSAGE 'Service failure occurred.' TYPE 'E'. ENDTRY.
  • For API details, see DescribeVoices in AWS SDK for SAP ABAP API reference.

The following code example shows how to use GetLexicon.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_ply->getlexicon( iv_name ). DATA(lo_lexicon) = oo_result->get_lexicon( ). IF lo_lexicon IS BOUND. DATA(lv_lex_name) = lo_lexicon->get_name( ). MESSAGE |Retrieved lexicon: { lv_lex_name }| TYPE 'I'. ENDIF. CATCH /aws1/cx_plylexiconnotfoundex. MESSAGE 'Lexicon not found.' TYPE 'E'. CATCH /aws1/cx_plyservicefailureex. MESSAGE 'Service failure occurred.' TYPE 'E'. ENDTRY.
  • For API details, see GetLexicon in AWS SDK for SAP ABAP API reference.

The following code example shows how to use GetSpeechSynthesisTask.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_ply->getspeechsynthesistask( iv_task_id ). DATA(lo_task) = oo_result->get_synthesistask( ). IF lo_task IS BOUND. DATA(lv_status) = lo_task->get_taskstatus( ). MESSAGE |Task status: { lv_status }| TYPE 'I'. ENDIF. CATCH /aws1/cx_plyinvalidtaskidex. MESSAGE 'Invalid task ID.' TYPE 'E'. CATCH /aws1/cx_plyservicefailureex. MESSAGE 'Service failure occurred.' TYPE 'E'. CATCH /aws1/cx_plysynthesistsknotf00. MESSAGE 'Synthesis task not found.' TYPE 'E'. ENDTRY.

The following code example shows how to use ListLexicons.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. oo_result = lo_ply->listlexicons( ). DATA(lt_lexicons) = oo_result->get_lexicons( ). DATA(lv_count) = lines( lt_lexicons ). MESSAGE |Found { lv_count } lexicons| TYPE 'I'. CATCH /aws1/cx_plyinvalidnexttokenex. MESSAGE 'Invalid NextToken.' TYPE 'E'. CATCH /aws1/cx_plyservicefailureex. MESSAGE 'Service failure occurred.' TYPE 'E'. ENDTRY.
  • For API details, see ListLexicons in AWS SDK for SAP ABAP API reference.

The following code example shows how to use ListSpeechSynthesisTasks.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. " Only pass optional parameters if they have values IF iv_max_results IS NOT INITIAL AND iv_status IS NOT INITIAL. oo_result = lo_ply->listspeechsynthesistasks( iv_maxresults = iv_max_results iv_status = iv_status ). ELSEIF iv_max_results IS NOT INITIAL. oo_result = lo_ply->listspeechsynthesistasks( iv_maxresults = iv_max_results ). ELSEIF iv_status IS NOT INITIAL. oo_result = lo_ply->listspeechsynthesistasks( iv_status = iv_status ). ELSE. oo_result = lo_ply->listspeechsynthesistasks( ). ENDIF. DATA(lt_tasks) = oo_result->get_synthesistasks( ). DATA(lv_count) = lines( lt_tasks ). MESSAGE |Found { lv_count } synthesis tasks| TYPE 'I'. CATCH /aws1/cx_plyinvalidnexttokenex. MESSAGE 'Invalid NextToken.' TYPE 'E'. CATCH /aws1/cx_plyservicefailureex. MESSAGE 'Service failure occurred.' TYPE 'E'. ENDTRY.

The following code example shows how to use PutLexicon.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. lo_ply->putlexicon( iv_name = iv_name iv_content = iv_content ). MESSAGE 'Lexicon created successfully.' TYPE 'I'. CATCH /aws1/cx_plyinvalidlexiconex. MESSAGE 'Invalid lexicon.' TYPE 'E'. CATCH /aws1/cx_plylexiconsizeexcdex. MESSAGE 'Lexicon size exceeded.' TYPE 'E'. CATCH /aws1/cx_plymaxlexemelengthe00. MESSAGE 'Maximum lexeme length exceeded.' TYPE 'E'. CATCH /aws1/cx_plymaxlexiconsnoexc00. MESSAGE 'Maximum number of lexicons exceeded.' TYPE 'E'. CATCH /aws1/cx_plyservicefailureex. MESSAGE 'Service failure occurred.' TYPE 'E'. CATCH /aws1/cx_plyunsuppedplsalpha00. MESSAGE 'Unsupported PLS alphabet.' TYPE 'E'. CATCH /aws1/cx_plyunsuppedplslangu00. MESSAGE 'Unsupported PLS language.' TYPE 'E'. ENDTRY.
  • For API details, see PutLexicon in AWS SDK for SAP ABAP API reference.

The following code example shows how to use StartSpeechSynthesisTask.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. " Only pass optional parameters if they have values IF iv_lang_code IS NOT INITIAL AND iv_s3_key_prefix IS NOT INITIAL. oo_result = lo_ply->startspeechsynthesistask( iv_engine = iv_engine iv_outputformat = iv_audio_format iv_outputs3bucketname = iv_s3_bucket iv_outputs3keyprefix = iv_s3_key_prefix iv_text = iv_text iv_voiceid = iv_voice_id iv_languagecode = iv_lang_code ). ELSEIF iv_lang_code IS NOT INITIAL. oo_result = lo_ply->startspeechsynthesistask( iv_engine = iv_engine iv_outputformat = iv_audio_format iv_outputs3bucketname = iv_s3_bucket iv_text = iv_text iv_voiceid = iv_voice_id iv_languagecode = iv_lang_code ). ELSEIF iv_s3_key_prefix IS NOT INITIAL. oo_result = lo_ply->startspeechsynthesistask( iv_engine = iv_engine iv_outputformat = iv_audio_format iv_outputs3bucketname = iv_s3_bucket iv_outputs3keyprefix = iv_s3_key_prefix iv_text = iv_text iv_voiceid = iv_voice_id ). ELSE. oo_result = lo_ply->startspeechsynthesistask( iv_engine = iv_engine iv_outputformat = iv_audio_format iv_outputs3bucketname = iv_s3_bucket iv_text = iv_text iv_voiceid = iv_voice_id ). ENDIF. MESSAGE 'Speech synthesis task started.' TYPE 'I'. CATCH /aws1/cx_plyinvalids3bucketex. MESSAGE 'Invalid S3 bucket.' TYPE 'E'. CATCH /aws1/cx_plyinvalidssmlex. MESSAGE 'Invalid SSML.' TYPE 'E'. CATCH /aws1/cx_plylexiconnotfoundex. MESSAGE 'Lexicon not found.' TYPE 'E'. CATCH /aws1/cx_plyservicefailureex. MESSAGE 'Service failure occurred.' TYPE 'E'. CATCH /aws1/cx_plytextlengthexcdex. MESSAGE 'Text length exceeded maximum.' TYPE 'E'. ENDTRY.

The following code example shows how to use SynthesizeSpeech.

SDK for SAP ABAP
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

TRY. " Only pass optional language code if it has a value IF iv_lang_code IS NOT INITIAL. oo_result = lo_ply->synthesizespeech( iv_engine = iv_engine iv_outputformat = iv_output_fmt iv_text = iv_text iv_voiceid = iv_voice_id iv_languagecode = iv_lang_code ). ELSE. oo_result = lo_ply->synthesizespeech( iv_engine = iv_engine iv_outputformat = iv_output_fmt iv_text = iv_text iv_voiceid = iv_voice_id ). ENDIF. MESSAGE 'Speech synthesized successfully.' TYPE 'I'. CATCH /aws1/cx_plyinvalidssmlex. MESSAGE 'Invalid SSML.' TYPE 'E'. CATCH /aws1/cx_plylexiconnotfoundex. MESSAGE 'Lexicon not found.' TYPE 'E'. CATCH /aws1/cx_plyservicefailureex. MESSAGE 'Service failure occurred.' TYPE 'E'. CATCH /aws1/cx_plytextlengthexcdex. MESSAGE 'Text length exceeded maximum.' TYPE 'E'. ENDTRY.