谷歌语音到文本依赖在运行时给出错误

时间:2018-05-24 10:58:49

标签: java spring-boot google-speech-api

我正在尝试使用google语音使用java spring boot来发送文本api。在他们的documentation中,它要求将以下依赖项添加到pom文件以下载所需的依赖项。

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-speech</artifactId>
  <version>0.46.0-alpha</version>
</dependency>

可以找到here

当我构建并运行项目时,项目会正常启动。

但是当我调用包含SpeechClient speech = SpeechClient.create()以下异常的方法时,会抛出异常。

io.grpc.ManagedChannelProvider$ProviderNotFoundException: No functional channel service provider found. Try adding a dependency on the grpc-okhttp or grpc-netty artifact 

然后我添加了依赖。

<dependency>
    <groupId>io.grpc</groupId>
    <artifactId>grpc-okhttp</artifactId>
    <version>1.11.0</version>
</dependency>     

<dependency>
    <groupId>io.grpc</groupId>
    <artifactId>grpc-netty</artifactId>
    <version>1.11.0</version>
</dependency>

一旦我添加了依赖项并尝试构建,就会出现如下构建失败,告诉我无法解决添加的依赖项。

 Failed to execute goal on project tts-samples: Could not resolve dependencies for project com.example.texttospeech:tts-samples:jar:2.0.1.RELEASE: Failed to collect dependencies for com.example.texttospeech:tts-samples:jar:2.0.1.RELEASE: Could not resolve version conflict among [com.google.cloud:google-cloud-speech:jar:0.47.0-alpha -> com.google.cloud:google-cloud-core-grpc:jar:1.29.0 -> io.grpc:grpc-protobuf:jar:1.10.1 -> io.grpc:grpc-core:jar:1.10.1, com.google.cloud:google-cloud-speech:jar:0.47.0-alpha -> com.google.cloud:google-cloud-core-grpc:jar:1.29.0 -> io.grpc:grpc-protobuf:jar:1.10.1 -> io.grpc:grpc-protobuf-lite:jar:1.10.1 -> io.grpc:grpc-core:jar:1.10.1, com.google.cloud:google-cloud-speech:jar:0.47.0-alpha -> io.grpc:grpc-netty-shaded:jar:1.10.1 -> io.grpc:grpc-core:jar:[1.10.1,1.10.1], com.google.cloud:google-cloud-speech:jar:0.47.0-alpha -> io.grpc:grpc-stub:jar:1.10.1 -> io.grpc:grpc-core:jar:1.10.1, com.google.cloud:google-cloud-speech:jar:0.47.0-alpha -> io.grpc:grpc-auth:jar:1.10.1 -> io.grpc:grpc-core:jar:[1.10.1,1.10.1], io.grpc:grpc-okhttp:jar:1.11.0 -> io.grpc:grpc-core:jar:[1.11.0,1.11.0], io.grpc:grpc-netty:jar:1.11.0 -> io.grpc:grpc-core:jar:[1.11.0,1.11.0]]

1 个答案:

答案 0 :(得分:0)

通过分解您发布的最后一个错误,看起来冲突实际上是在版本中而不是在依赖项中。 (注意用***包围的2行:

com.google.cloud:google-cloud-speech:jar:0.47.0-alpha
    io.grpc:grpc-netty-shaded:jar:1.10.1, io.grpc:grpc-stub:jar:1.10.1, io.grpc:grpc-auth:jar:1.10.1
        ***io.grpc:grpc-core:jar:[1.10.1,1.10.1],*** 
io.grpc:grpc-okhttp:jar:1.11.0, io.grpc:grpc-netty:jar:1.11.
        ***io.grpc:grpc-core:jar:[1.11.0,1.11.0]***

您使用的google-cloud-speech库取决于依赖于grpc-core 1.10.1的库,而新的依赖项使用的是grpc-core 1.11.0。将版本从1.11.0更改为1.10.1,问题可能已解决。你会得到这样的东西:

<dependency>
    <groupId>io.grpc</groupId>
    <artifactId>grpc-okhttp</artifactId>
    <version>1.10.1</version>
</dependency>     

<dependency>
    <groupId>io.grpc</groupId>
    <artifactId>grpc-netty</artifactId>
    <version>1.10.1</version>
</dependency>