使用Google Speech-to-Text API时出现Python错误:startswitch()至少需要1个参数



我是Python的新手,希望为Speech to Text实现[谷歌API提供的代码][1]。在添加我的bucket名称后,我收到这个错误:

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

我已经尝试将路径函数转换为字符串,但仍然收到错误。我错过了什么?请参阅下面的代码。

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

我想你想要这样的东西:

path.startsWith("gs://example-june-webinar")

这将在您的案例中返回True,您可以将其用于您的用例。

最新更新