英文:
Module 'swagger_client' has no attribute 'CustomSpeechTranscriptionsApi'
问题
我使用 Microsoft 官方的 GitHub 存储库来设置 从 Python 使用 Azure 语音服务批处理转录 API。
我在 main.py 的第 142 行收到一个错误,其中指出:
AttributeError: module 'swagger_client' has no attribute 'CustomSpeechTranscriptionsApi'
我猜这与对 swagger_client 进行的最近更改有关。如何解决这个问题,有什么想法吗?
我已经按照下面的线程进行了调试,并注意到其他一些人也报告了相同的问题,但没有什么帮助,
Thread 1, Thread 2
为了调试,我在抛出上述错误之前执行了 print(dir(swagger_client))
,以下是打印语句的输出:
['ApiClient', 'ApiSpeechtotextV30DatasetsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30EndpointsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30EvaluationsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30ModelsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30ProjectsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30TranscriptionsLocalesGet200ApplicationJsonResponse', 'Component', 'Configuration', 'Dataset', 'DatasetProperties', 'DatasetUpdate', 'DefaultApi', 'Endpoint', 'EndpointLinks', 'EndpointProperties', 'EndpointPropertiesUpdate', 'EndpointUpdate', 'EntityError', 'EntityReference', 'Error', 'ErrorContent', 'ErrorDetail', 'Evaluation', 'EvaluationProperties', 'EvaluationUpdate', 'File', 'FileLinks', 'FileProperties', 'HealthStatus', 'InnerError', 'InnerErrorV2', 'InternalModel', 'Links', 'ManagementModel', 'ManagementModelArray', 'ManagementModelProperties', 'Model', 'ModelCopy', 'ModelDeprecationDates', 'ModelFile', 'ModelLinks', 'ModelManifest', 'ModelProperties', 'ModelUpdate', 'PaginatedDatasets', 'PaginatedEndpoints', 'PaginatedEvaluations', 'PaginatedFiles', 'PaginatedModels', 'PaginatedProjects', 'PaginatedTranscriptions', 'PaginatedWebHooks', 'Project', 'ProjectLinks', 'ProjectProperties', 'ProjectUpdate', 'Transcription', 'TranscriptionProperties', 'TranscriptionUpdate', 'WebHook', 'WebHookEvents', 'WebHookEvents1', 'WebHookLinks', 'WebHookProperties', 'WebHookPropertiesUpdate', 'WebHookUpdate', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'absolute_import', 'api', 'api_client', 'configuration', 'models', 'rest']
英文:
I'm using Microsoft's official GitHub repository to set up Azure Speech Services Batch Transcription API from Python
I receive an error from line number 142 in main.py which states
AttributeError: module 'swagger_client' has no attribute 'CustomSpeechTranscriptionsApi'
I suppose this has to do with the recent changes made to the swagger_client. How to fix this issue any thoughts?
I already followed the below threads and noticed a few others also reported the same issue but nothing helped,<br>
Thread 1, Thread 2
To debug I gave print(dir(swagger_client))
before it throws the above error and here is the output of the print statement
['ApiClient', 'ApiSpeechtotextV30DatasetsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30EndpointsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30EvaluationsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30ModelsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30ProjectsLocalesGet200ApplicationJsonResponse', 'ApiSpeechtotextV30TranscriptionsLocalesGet200ApplicationJsonResponse', 'Component', 'Configuration', 'Dataset', 'DatasetProperties', 'DatasetUpdate', 'DefaultApi', 'Endpoint', 'EndpointLinks', 'EndpointProperties', 'EndpointPropertiesUpdate', 'EndpointUpdate', 'EntityError', 'EntityReference', 'Error', 'ErrorContent', 'ErrorDetail', 'Evaluation', 'EvaluationProperties', 'EvaluationUpdate', 'File', 'FileLinks', 'FileProperties', 'HealthStatus', 'InnerError', 'InnerErrorV2', 'InternalModel', 'Links', 'ManagementModel', 'ManagementModelArray', 'ManagementModelProperties', 'Model', 'ModelCopy', 'ModelDeprecationDates', 'ModelFile', 'ModelLinks', 'ModelManifest', 'ModelProperties', 'ModelUpdate', 'PaginatedDatasets', 'PaginatedEndpoints', 'PaginatedEvaluations', 'PaginatedFiles', 'PaginatedModels', 'PaginatedProjects', 'PaginatedTranscriptions', 'PaginatedWebHooks', 'Project', 'ProjectLinks', 'ProjectProperties', 'ProjectUpdate', 'Transcription', 'TranscriptionProperties', 'TranscriptionUpdate', 'WebHook', 'WebHookEvents', 'WebHookEvents1', 'WebHookLinks', 'WebHookProperties', 'WebHookPropertiesUpdate', 'WebHookUpdate', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'absolute_import', 'api', 'api_client', 'configuration', 'models', 'rest']
答案1
得分: 1
Here is the translation of the provided content:
> AttributeError: module 'swagger_client' has no attribute 'CustomSpeechTranscriptionsApi'
上述错误说明您没有正确安装**`swagger_client`**。
请确保您已正确下载了Swagger的API客户端库,并使用pip安装python-client模块:`pip install path/to/package/python-client`
我按照相同的[Github文档](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/samples/batch/python)和相同的代码能够从音频文件中获取到转录。
我还使用**`print(dir(swagger_client))`** 检查,我能够获取到**`CustomSpeechTranscriptionsApi`** 属性,我的版本是**`swagger_client = 1.0.0`**。
![输入图像描述](https://i.imgur.com/gw76NHO.png)
**代码:**
def transcribe():
logging.info("启动转录客户端...")
# 配置API密钥授权:subscription_key
configuration = swagger_client.Configuration()
configuration.api_key["Ocp-Apim-Subscription-Key"] = SUBSCRIPTION_KEY
configuration.host = f"https://{SERVICE_REGION}.api.cognitive.microsoft.com/speechtotext/v3.1"
# 创建客户端对象并进行身份验证
client = swagger_client.ApiClient(configuration)
# 创建转录API类的实例
api = swagger_client.CustomSpeechTranscriptionsApi(api_client=client)
properties = swagger_client.TranscriptionProperties()
transcription_definition = transcribe_from_single_blob(RECORDINGS_BLOB_URI, properties)
created_transcription, status, headers = api.transcriptions_create_with_http_info(transcription=transcription_definition)
transcription_id = headers["location"].split("/")[-1]
# 记录有关创建的转录的信息。如果您需要支持,请包括此信息。
logging.info(f"在区域{SERVICE_REGION}创建了新的转录,ID为'{transcription_id}'")
logging.info("检查状态...")
completed = False
while not completed:
# 等待5秒钟,然后刷新转录状态
time.sleep(5)
transcription = api.transcriptions_get(transcription_id)
logging.info(f"转录状态:{transcription.status}")
if transcription.status in ("Failed", "Succeeded"):
completed = True
if transcription.status == "Succeeded":
pag_files = api.transcriptions_list_files(transcription_id)
for file_data in _paginate(api, pag_files):
if file_data.kind != "Transcription":
continue
audiofilename = file_data.name
results_url = file_data.links.content_url
results = requests.get(results_url)
logging.info(f"{audiofilename}的结果:\n{results.content.decode('utf-8')}")
elif transcription.status == "Failed":
logging.info(f"转录失败:{transcription.properties.error.message}")
if __name__ == "__main__":
transcribe()
输出:
2023年5月8日 上午11:10:07印度标准时间 启动转录客户端...
2023年5月8日 上午11:10:08印度标准时间 在区域<region>创建了新的转录,ID为'your id'
2023年5月8日 上午11:10:08印度标准时间 检查状态...
2023年5月8日 上午11:10:13印度标准时间 转录状态:Running
2023年5月8日 上午11:10:19印度标准时间 转录状态:Succeeded
2023年5月8日 上午11:10:20印度标准时间 contenturl_0.json的结果:
{
"source": "https://<storageaccountname>.blob.core.windows.net/test/harvard.wav?<sas-token>",
"timestamp": "2023-05-08T05:40:15Z",
"durationInTicks": 183500000,
"duration": "PT18.35S",
"combinedRecognizedPhrases": [
{
"channel": 0,
"lexical": "陈旧的啤酒味仍然存在,需要热度才能散发出气味。冷浸泡可以恢复健康和朝气。咸腌菜与火腿玉米卷搭配得很好。阿尔帕斯托尔是我最喜欢的。富有朝气的食物是热十字包。",
"itn": "陈旧的啤酒味仍然存在,需要热度才能散发出气味。冷浸泡可以恢复健康和朝气。咸腌菜与火腿玉米卷搭配得很好。阿尔帕斯托尔是我最喜欢的。富有朝气的食物是热十字包。",
"maskedITN": "陈旧的啤酒味仍然存在,需要热度才能散发出气味。冷浸泡可以恢复健康和朝气。咸腌菜与火腿玉米卷搭配得很好。阿尔帕斯托尔是我最喜欢的。富有朝气的食物是热十字包。",
"display": "陈旧的啤酒味仍然存在,需要热度才能散发出气味。冷浸泡可以恢复健康和朝气。咸腌菜与火腿玉米卷搭配得很好。阿尔帕斯托尔是我最喜欢的。富有朝气的食物是热十字包。"
},
{
"channel": 1,
"lexical": "陈旧的啤酒味仍然存在,需要热度才能散发出气味。冷浸泡可以恢复健康和
英文:
> AttributeError: module 'swagger_client' has no attribute 'CustomSpeechTranscriptionsApi
The above error states you have not correctly installed swagger_client
.
Make sure you have downloaded the API client library with Swagger correctly and the Python environment using pip to install the python-client module: pip install path/to/package/python-client
I followed the same Github-document with the same code can able to get the transcription from the audio file.
I also checked with print(dir(swagger_client)
i can able to get the CustomSpeechTranscriptionsApi
attribute and my version swagger_client = 1.0.0
.
Code:
def transcribe():
logging.info("Starting transcription client...")
# configure API key authorization: subscription_key
configuration = swagger_client.Configuration()
configuration.api_key["Ocp-Apim-Subscription-Key"] = SUBSCRIPTION_KEY
configuration.host = f"https://{SERVICE_REGION}.api.cognitive.microsoft.com/speechtotext/v3.1"
# create the client object and authenticate
client = swagger_client.ApiClient(configuration)
# create an instance of the transcription api class
api = swagger_client.CustomSpeechTranscriptionsApi(api_client=client)
properties = swagger_client.TranscriptionProperties()
transcription_definition = transcribe_from_single_blob(RECORDINGS_BLOB_URI, properties)
created_transcription, status, headers = api.transcriptions_create_with_http_info(transcription=transcription_definition)
transcription_id = headers["location"].split("/")[-1]
# Log information about the created transcription. If you should ask for support, please
# include this information.
logging.info(f"Created new transcription with id '{transcription_id}' in region {SERVICE_REGION}")
logging.info("Checking status.")
completed = False
while not completed:
# wait for 5 seconds before refreshing the transcription status
time.sleep(5)
transcription = api.transcriptions_get(transcription_id)
logging.info(f"Transcriptions status: {transcription.status}")
if transcription.status in ("Failed", "Succeeded"):
completed = True
if transcription.status == "Succeeded":
pag_files = api.transcriptions_list_files(transcription_id)
for file_data in _paginate(api, pag_files):
if file_data.kind != "Transcription":
continue
audiofilename = file_data.name
results_url = file_data.links.content_url
results = requests.get(results_url)
logging.info(f"Results for {audiofilename}:\n{results.content.decode('utf-8')}")
elif transcription.status == "Failed":
logging.info(f"Transcription failed: {transcription.properties.error.message}")
if __name__ == "__main__":
transcribe()
Output:
05/08/2023 11:10:07 AM India Standard Time Starting transcription client...
05/08/2023 11:10:08 AM India Standard Time Created new transcription with id 'your id' in region <region>05/08/2023 11:10:08 AM India Standard Time Checking status.
05/08/2023 11:10:13 AM India Standard Time Transcriptions status: Running
05/08/2023 11:10:19 AM India Standard Time Transcriptions status: Succeeded
05/08/2023 11:10:20 AM India Standard Time Results for contenturl_0.json:
{
"source": "https://<storageaccountname>.blob.core.windows.net/test/harvard.wav?<sas-token>",
"timestamp": "2023-05-08T05:40:15Z",
"durationInTicks": 183500000,
"duration": "PT18.35S",
"combinedRecognizedPhrases": [
{
"channel": 0,
"lexical": "the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle tastes fine with ham tacos al pastor are my favorite a zestful food is the hot cross bun",
"itn": "the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle tastes fine with ham tacos al pastor are my favorite a zestful food is the hot cross bun",
"maskedITN": "the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle tastes fine with ham tacos al pastor are my favorite a zestful food is the hot cross bun",
"display": "The stale smell of old beer lingers. It takes heat to bring out the odor. A cold dip restores health and zest. A salt pickle tastes fine with ham tacos. Al pastor are my favorite. A zestful food is the hot cross bun."
},
{
"channel": 1,
"lexical": "the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle tastes fine with ham tacos al pastor are my favorite a zestful food is the hot cross bun",
"itn": "the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle tastes fine with ham tacos al pastor are my favorite a zestful food is the hot cross bun",
"maskedITN": "the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle tastes fine with ham tacos al pastor are my favorite a zestful food is the hot cross bun",
"display": "The stale smell of old beer lingers. It takes heat to bring out the odor. A cold dip restores health and zest. A salt pickle tastes fine with ham tacos. Al pastor are my favorite. A zestful food is the hot cross bun
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论