“swagger_client”模块没有”CustomSpeechTranscriptionsApi”属性。

huangapple go评论85阅读模式
英文:

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

[&#39;ApiClient&#39;, &#39;ApiSpeechtotextV30DatasetsLocalesGet200ApplicationJsonResponse&#39;, &#39;ApiSpeechtotextV30EndpointsLocalesGet200ApplicationJsonResponse&#39;, &#39;ApiSpeechtotextV30EvaluationsLocalesGet200ApplicationJsonResponse&#39;, &#39;ApiSpeechtotextV30ModelsLocalesGet200ApplicationJsonResponse&#39;, &#39;ApiSpeechtotextV30ProjectsLocalesGet200ApplicationJsonResponse&#39;, &#39;ApiSpeechtotextV30TranscriptionsLocalesGet200ApplicationJsonResponse&#39;, &#39;Component&#39;, &#39;Configuration&#39;, &#39;Dataset&#39;, &#39;DatasetProperties&#39;, &#39;DatasetUpdate&#39;, &#39;DefaultApi&#39;, &#39;Endpoint&#39;, &#39;EndpointLinks&#39;, &#39;EndpointProperties&#39;, &#39;EndpointPropertiesUpdate&#39;, &#39;EndpointUpdate&#39;, &#39;EntityError&#39;, &#39;EntityReference&#39;, &#39;Error&#39;, &#39;ErrorContent&#39;, &#39;ErrorDetail&#39;, &#39;Evaluation&#39;, &#39;EvaluationProperties&#39;, &#39;EvaluationUpdate&#39;, &#39;File&#39;, &#39;FileLinks&#39;, &#39;FileProperties&#39;, &#39;HealthStatus&#39;, &#39;InnerError&#39;, &#39;InnerErrorV2&#39;, &#39;InternalModel&#39;, &#39;Links&#39;, &#39;ManagementModel&#39;, &#39;ManagementModelArray&#39;, &#39;ManagementModelProperties&#39;, &#39;Model&#39;, &#39;ModelCopy&#39;, &#39;ModelDeprecationDates&#39;, &#39;ModelFile&#39;, &#39;ModelLinks&#39;, &#39;ModelManifest&#39;, &#39;ModelProperties&#39;, &#39;ModelUpdate&#39;, &#39;PaginatedDatasets&#39;, &#39;PaginatedEndpoints&#39;, &#39;PaginatedEvaluations&#39;, &#39;PaginatedFiles&#39;, &#39;PaginatedModels&#39;, &#39;PaginatedProjects&#39;, &#39;PaginatedTranscriptions&#39;, &#39;PaginatedWebHooks&#39;, &#39;Project&#39;, &#39;ProjectLinks&#39;, &#39;ProjectProperties&#39;, &#39;ProjectUpdate&#39;, &#39;Transcription&#39;, &#39;TranscriptionProperties&#39;, &#39;TranscriptionUpdate&#39;, &#39;WebHook&#39;, &#39;WebHookEvents&#39;, &#39;WebHookEvents1&#39;, &#39;WebHookLinks&#39;, &#39;WebHookProperties&#39;, &#39;WebHookPropertiesUpdate&#39;, &#39;WebHookUpdate&#39;, &#39;__builtins__&#39;, &#39;__cached__&#39;, &#39;__doc__&#39;, &#39;__file__&#39;, &#39;__loader__&#39;, &#39;__name__&#39;, &#39;__package__&#39;, &#39;__path__&#39;, &#39;__spec__&#39;, &#39;absolute_import&#39;, &#39;api&#39;, &#39;api_client&#39;, &#39;configuration&#39;, &#39;models&#39;, &#39;rest&#39;]

答案1

得分: 1

Here is the translation of the provided content:

&gt; 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.

“swagger_client”模块没有”CustomSpeechTranscriptionsApi”属性。

Code:

def transcribe():
    logging.info(&quot;Starting transcription client...&quot;)

    # configure API key authorization: subscription_key
    configuration = swagger_client.Configuration()
    configuration.api_key[&quot;Ocp-Apim-Subscription-Key&quot;] = SUBSCRIPTION_KEY
    configuration.host = f&quot;https://{SERVICE_REGION}.api.cognitive.microsoft.com/speechtotext/v3.1&quot;

    # 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[&quot;location&quot;].split(&quot;/&quot;)[-1]

    # Log information about the created transcription. If you should ask for support, please
    # include this information.
    logging.info(f&quot;Created new transcription with id &#39;{transcription_id}&#39; in region {SERVICE_REGION}&quot;)

    logging.info(&quot;Checking status.&quot;)

    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&quot;Transcriptions status: {transcription.status}&quot;)

        if transcription.status in (&quot;Failed&quot;, &quot;Succeeded&quot;):
            completed = True

        if transcription.status == &quot;Succeeded&quot;:
            pag_files = api.transcriptions_list_files(transcription_id)
            for file_data in _paginate(api, pag_files):
                if file_data.kind != &quot;Transcription&quot;:
                    continue

                audiofilename = file_data.name
                results_url = file_data.links.content_url
                results = requests.get(results_url)
                logging.info(f&quot;Results for {audiofilename}:\n{results.content.decode(&#39;utf-8&#39;)}&quot;)
        elif transcription.status == &quot;Failed&quot;:
            logging.info(f&quot;Transcription failed: {transcription.properties.error.message}&quot;)


if __name__ == &quot;__main__&quot;:
    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 &#39;your id&#39; in region &lt;region&gt;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:
{
  &quot;source&quot;: &quot;https://&lt;storageaccountname&gt;.blob.core.windows.net/test/harvard.wav?&lt;sas-token&gt;&quot;,
  &quot;timestamp&quot;: &quot;2023-05-08T05:40:15Z&quot;,
  &quot;durationInTicks&quot;: 183500000,
  &quot;duration&quot;: &quot;PT18.35S&quot;,
  &quot;combinedRecognizedPhrases&quot;: [
    {
      &quot;channel&quot;: 0,
      &quot;lexical&quot;: &quot;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&quot;,
      &quot;itn&quot;: &quot;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&quot;,
      &quot;maskedITN&quot;: &quot;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&quot;,
      &quot;display&quot;: &quot;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.&quot;
    },
    {
      &quot;channel&quot;: 1,
      &quot;lexical&quot;: &quot;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&quot;,
      &quot;itn&quot;: &quot;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&quot;,
      &quot;maskedITN&quot;: &quot;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&quot;,
      &quot;display&quot;: &quot;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

“swagger_client”模块没有”CustomSpeechTranscriptionsApi”属性。

huangapple
  • 本文由 发表于 2023年5月7日 07:48:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76191661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定