首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Google Speech-to-Text API时出现Python错误: startswith()至少接受1个参数(给定为0)

使用Google Speech-to-Text API时出现Python错误: startswith()至少接受1个参数(给定为0)
EN

Stack Overflow用户
提问于 2021-07-06 09:06:20
回答 1查看 36关注 0票数 0

我是Python的新手,希望实现Google API提供的用于语音到文本的代码。添加存储桶名称后,我收到以下错误:

TypeError: startswith() takes at least 1 argument (0 given)

我尝试将path函数转换为字符串,但仍然收到错误。我遗漏了什么?请看我下面的代码。

代码语言:javascript
复制
    parser = argparse.ArgumentParser(
        description='Speech to text from video file', formatter_class=argparse.RawDescriptionHelpFormatter
    )
    parser.add_argument('--path', help="File or GCS path for audio file to be recognized")
    parser.add_argument(
        "--model",
        help="The speech recognition model to use",
        choices=["command_and_search", "phone_call", "video", "default"],
        default="default",
    )

    args = parser.parse_args()
    print(args) 
    
    path=("gs://parabilis-june-webinar")
    path.startswith().toString().startsWith("gs://example-june-webinar")

    if args.path.startswith("gs://example-webinar"):
            transcribe_model_selection_gcs(args.path, args.model)
    else:
            transcribe_model_selection(args.path, args.model)```


  [1]: https://github.com/googleapis/python-speech/blob/HEAD/samples/snippets/transcribe_model_selection.py
EN

回答 1

Stack Overflow用户

发布于 2021-07-06 10:46:34

我认为你需要这样的东西:

代码语言:javascript
复制
path.startsWith("gs://example-june-webinar")

这将在您的用例中返回True,您可以在您的用例中使用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68263389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档