我在S3中有一个音频文件。
我不知道音频文件的语言。所以我需要将IdentifyLanguage用于start_transcription_job()。
LanguageCode将是空的,因为我不知道音频文件的语言。
环境
使用Python3.8运行时,boto3版本1.16.5,botocore版本:1.19.5,没有Lambda层。
这里是我的转录作业代码:
mediaFileUri = 's3://'+ bucket_name+'/'+prefixKey
transcribe_client = boto3.client('transcribe')
response = transcribe_client.start_transcription_job(
TranscriptionJobName="abc",
IdentifyLanguage=True,
Media={
'MediaFileUri':mediaFileUri
},
),那么我得到了一个错误:
{
"errorMessage": "Parameter validation failed:\nMissing required parameter in input: \"LanguageCode\"\nUnknown parameter in input: \"IdentifyLanguage\", must be one of: TranscriptionJobName, LanguageCode, MediaSampleRateHertz, MediaFormat, Media, OutputBucketName, OutputEncryptionKMSKeyId, Settings, ModelSettings, JobExecutionSettings, ContentRedaction",
"errorType": "ParamValidationError",
"stackTrace": [
" File \"/var/task/app.py\", line 27, in TranscribeSoundToWordHandler\n response = response = transcribe_client.start_transcription_job(\n",
" File \"/var/runtime/botocore/client.py\", line 316, in _api_call\n return self._make_api_call(operation_name, kwargs)\n",
" File \"/var/runtime/botocore/client.py\", line 607, in _make_api_call\n request_dict = self._convert_to_request_dict(\n",
" File \"/var/runtime/botocore/client.py\", line 655, in _convert_to_request_dict\n request_dict = self._serializer.serialize_to_request(\n",
" File \"/var/runtime/botocore/validate.py\", line 297, in serialize_to_request\n raise ParamValidationError(report=report.generate_report())\n"
]
}有了这个错误,意味着我必须指定LanguageCode,而IdentifyLanguage是一个无效的参数。
100%确保音频文件存在于S3中。但是如果没有LanguageCode,它就不能工作,而且IdentifyLanguage参数是未知参数
I使用SAM应用程序在本地使用以下命令进行测试:
sam local invoke MyHandler -e lambda\TheDirectory\event.json我cdk deploy,并签入Aws Lambda控制台,测试它相同的events.json,但仍然得到相同的错误。
我认为这是Lambda执行环境,我没有使用任何Lambda层。
我从Aws转录:看这个文档
这是boto3的文档
明确声明LanguageCode不是必需的,IdentifyLanguage是一个有效的参数。
那我错过了什么?对此有什么想法吗?我该怎么办?
更新:
我一直在网上搜索和询问情侣,我认为我应该先构建函数容器,让SAM将boto3打包到容器中。
所以我要做的是,cdk synth一个模板文件:
cdk synth --no-staging > template.yaml然后:
sam build --use-container
sam local invoke MyHandler78A95900 -e lambda\TheDirectory\event.json但是,我还是得到了同样的错误,但是也发布了堆栈跟踪。
[ERROR] ParamValidationError: Parameter validation failed:
Missing required parameter in input: "LanguageCode"
Unknown parameter in input: "IdentifyLanguage", must be one of: TranscriptionJobName, LanguageCode, MediaSampleRateHertz, MediaFormat, Media, OutputBucketName, OutputEncryptionKMSKeyId, Settings, JobExecutionSettings, ContentRedaction
Traceback (most recent call last):
File "/var/task/app.py", line 27, in TranscribeSoundToWordHandler
response = response = transcribe_client.start_transcription_job(
File "/var/runtime/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 607, in _make_api_call
request_dict = self._convert_to_request_dict(
File "/var/runtime/botocore/client.py", line 655, in _convert_to_request_dict
request_dict = self._serializer.serialize_to_request(
File "/var/runtime/botocore/validate.py", line 297, in serialize_to_request
raise ParamValidationError(report=report.generate_report())真的不知道我做错了什么。我还报道了一个github在此发行,但似乎无法复制这个问题。
主要问题/问题:
无法start_transription_job
LanguageCodeIdentifyLanguage=True造成这种情况的原因是什么,以及我如何解决这个问题(不知道音频文件的语言,我想识别音频文件的语言而不给出LanguageCode)?
发布于 2020-10-30 00:49:20
最后,我注意到这是因为我的打包lambda函数由于某种原因没有被上传。这是我在得到几个人的帮助后如何解决的。
首先修改CDK堆栈,它定义了我的lambda函数,如下所示:
from aws_cdk import (
aws_lambda as lambda_,
core
)
from aws_cdk.aws_lambda_python import PythonFunction
class MyCdkStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
# define lambda
my_lambda = PythonFunction(
self, 'MyHandler',
entry='lambda/MyHandler',
index='app.py',
runtime=lambda_.Runtime.PYTHON_3_8,
handler='MyHandler',
timeout=core.Duration.seconds(10)
)这将使用aws-lambda-python模块,它将处理将所有所需模块安装到坞中。
下一步,cdk合成一个模板文件。
cdk synth --no-staging > template.yaml 此时,它将捆绑在entry路径中定义的PythonFunction路径中的所有内容,并在该entry路径中安装requirements.txt中定义的所有必要的依赖项。
下一步,构建码头容器
$ sam build --use-container确保根目录中的template.yaml文件。这将构建一个码头容器,工件将在我的根目录中的.aws-sam/build目录中构建。
最后一步,使用sam:调用函数
sam local invoke MyHandler78A95900 -e path\to\event.json现在,正如我在上面的问题中所述,现在终于成功地调用了start_transcription_job,没有任何错误。
结论:
pip install boto3,这只会在我的本地系统中安装boto3。sam local invoke第一次构建容器的情况下,使用sam build --use-containersam build,但在这一点上,我并没有将在requirements.txt中定义的内容绑定到.aws-sam/build中,因此需要像上面提到的那样使用aws-lambda-python模块。发布于 2020-10-27 14:45:25
检查您是否正在使用最新的boto3版本。
boto3.__version__
'1.16.5'我试过了而且成功了。
import boto3
transcribe = boto3.client('transcribe')
response = transcribe.start_transcription_job(TranscriptionJobName='Test-20201-27',IdentifyLanguage=True,Media={'MediaFileUri':'s3://BucketName/DemoData/Object.mp4'})
print(response)
{
"TranscriptionJob": {
"TranscriptionJobName": "Test-20201-27",
"TranscriptionJobStatus": "IN_PROGRESS",
"Media": {
"MediaFileUri": "s3://BucketName/DemoData/Object.mp4"
},
"StartTime": "datetime.datetime(2020, 10, 27, 15, 41, 2, 599000, tzinfo=tzlocal())",
"CreationTime": "datetime.datetime(2020, 10, 27, 15, 41, 2, 565000, tzinfo=tzlocal())",
"IdentifyLanguage": "True"
},
"ResponseMetadata": {
"RequestId": "9e4f94a4-20e4-4ca0-9c6e-e21a8934084b",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"content-type": "application/x-amz-json-1.1",
"date": "Tue, 27 Oct 2020 14:41:02 GMT",
"x-amzn-requestid": "9e4f94a4-20e4-4ca0-9c6e-e21a8934084b",
"content-length": "268",
"connection": "keep-alive"
},
"RetryAttempts": 0
}
}https://stackoverflow.com/questions/64555481
复制相似问题