本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用适用于 SAP 的软件开发工具包的 Amazon Polly 示例 ABAP
以下代码示例向您展示了如何使用适用于 SAP ABAP 的 AWS 软件开发工具包和 Amazon Polly 来执行操作和实现常见场景。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示了如何使用 DeleteLexicon。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用DeleteLexicon于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 DescribeVoices。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用DescribeVoices于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 GetLexicon。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用GetLexicon于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 GetSpeechSynthesisTask。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用GetSpeechSynthesisTask于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 ListLexicons。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用ListLexicons于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 ListSpeechSynthesisTasks。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用ListSpeechSynthesisTasks于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 PutLexicon。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用PutLexicon于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 StartSpeechSynthesisTask。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用StartSpeechSynthesisTask于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 SynthesizeSpeech。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用SynthesizeSpeech于 S AP 的AWS SDK ABAP API 参考。
-