Search code examples
javaspring-bootgoogle-speech-api

google speech to text dependency gives errors at runtime


I am trying to use google speech to text api using java spring boot. In their documentation it askes to add the following dependency to the pom file to download the needed dependencies.

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

This can be found here.

When I build and run the project, the project gets started normally.

But when I call the method containing SpeechClient speech = SpeechClient.create() below exception is thrown.

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

Then I added that dependency.

<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>

Once I added that dependency also and try to build, a BUILD FAILURE occurred as follows telling me that could not resolve the added dependencies.

 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]]

Solution

  • By breaking down the last error you posted, it looks like the conflict is actually in the versions rather than in the dependencies. (Note the 2 lines surrounded with ***:

    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]***
    

    The google-cloud-speech library you are using depends on libraries that depend on the grpc-core 1.10.1 while the new dependencies are using grpc-core 1.11.0. Change the versions from 1.11.0 to 1.10.1 and the problem might be solved. You will have something like this:

    <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>