Composer 无法下载 Google 个文本转语音库

Composer fails to download Google Text-To-Speech library

我正在尝试导入 Google 的文本转语音库

composer require google/cloud-text-to-speech

但是我得到这个错误

Using version ^0.4.4 for google/cloud-text-to-speech
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for google/cloud-text-to-speech ^0.4.4 -> satisfiable by google/cloud-text-to-speech[v0.4.4].
    - Conclusion: don't install google/gax 0.37.0
    - google/cloud-text-to-speech v0.4.4 requires google/gax ^1.0 -> satisfiable by google/gax[1.0.0, 1.0.1, 1.0.2, 1.0.3].
    - Can only install one of: google/gax[1.0.0, 0.37.0].
    - Can only install one of: google/gax[1.0.1, 0.37.0].
    - Can only install one of: google/gax[1.0.2, 0.37.0].
    - Can only install one of: google/gax[1.0.3, 0.37.0].
    - Installation request for google/gax (locked at 0.37.0) -> satisfiable by google/gax[0.37.0].


Installation failed, reverting ./composer.json to its original content.

我该如何解决这个问题?是否有任何可用的库可以在不使用 Composer 的情况下下载?

您或您项目中的另一个依赖项似乎也需要 google/gax,但在旧版本中。您可以使用 why 命令找出 google/gax 被锁定在版本 0.37.0 的原因:

composer why google/gax

这应该会告诉您它是作为根依赖项安装的,这意味着您明确安装了它还是哪个其他依赖项需要它。

然后你必须找出那个依赖是否有更新版本,所以你可以升级那个依赖以便能够使用更新版本的google/gax。如果您确定更新是安全的,只需将两个扩展添加到 require 命令或先更新依赖项,然后再次尝试 require google/cloud-text-to-speech

Composer 还提供了一种自动为您更新所有依赖项的方法,但这显然存在从更新中引入重大更改的风险,因此请谨慎使用:

--update-with-dependencies      Allows inherited dependencies to be updated, except those that are root requirements.
--update-with-all-dependencies  Allows all inherited dependencies to be updated, including those that are root requirements.

所以运行:

composer require --update-with-all-dependencies google/cloud-text-to-speech

应该以支持所需版本 google/gax 的方式更新您的应用程序,以便安装 google/cloud-text-to-speech。这可能会导致其他依赖项被更新,您可以检查输出以查看哪些受到影响。