watson-developer-cloud / java-sdk

:1st_place_medal: Java SDK to use the IBM Watson services.
http://watson-developer-cloud.github.io/java-sdk/
Apache License 2.0
593 stars 532 forks source link

Invalid POM #466

Closed shikida closed 8 years ago

shikida commented 8 years ago

I've created a brand maven project in eclipse using this pom

[project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"]
    [modelVersion]4.0.0[/modelVersion]
    [groupId]S2T[/groupId]
    [artifactId]S2T[/artifactId]
    [version]0.0.1-SNAPSHOT[/version]
    [build]
        [sourceDirectory]src[/sourceDirectory]
        [plugins]
            [plugin]
                [artifactId]maven-compiler-plugin[/artifactId]
                [version]3.5.1[/version]
                [configuration]
                    [source]1.8[/source]
                    [target]1.8[/target]
                [/configuration]
            [/plugin]
        [/plugins]
    [/build]
    [dependencies]
        [dependency]
            [groupId]com.ibm.watson.developer_cloud[/groupId]
            [artifactId]java-sdk[/artifactId]
            [version]3.5.0[/version]
        [/dependency]
    [/dependencies]
[/project]

I'm getting the "missing artifact" error

In fact, if I go to

https://mvnrepository.com/artifact/com.ibm.watson.developer_cloud/java-wrapper

last version is 1.1.1

however, the same site says these are valid

[dependency]
    [groupId]com.ibm.watson.developer_cloud[/groupId]
    [artifactId]core[/artifactId]
    [version]3.4.0[/version]
[/dependency]

(not 3.5.0 as the main github page says)

So I am using the following POM

[project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"]
    [modelVersion]4.0.0[/modelVersion]
    [groupId]S2T[/groupId]
    [artifactId]S2T[/artifactId]
    [version]0.0.1-SNAPSHOT[/version]
    [build]
        [sourceDirectory]src[/sourceDirectory]
        [plugins]
            [plugin]
                [artifactId]maven-compiler-plugin[/artifactId]
                [version]3.5.1[/version]
                [configuration]
                    [source]1.8[/source]
                    [target]1.8[/target]
                [/configuration]
            [/plugin]
        [/plugins]
    [/build]
    [dependencies]
        [dependency]
            [groupId]com.ibm.watson.developer_cloud[/groupId]
            [artifactId]core[/artifactId]
            [version]3.4.0[/version]
        [/dependency]
        [dependency]
            [groupId]com.ibm.watson.developer_cloud[/groupId]
            [artifactId]speech-to-text[/artifactId]
            [version]3.4.0[/version]
        [/dependency]
    [/dependencies]
[/project]

and then I try to run

import java.io.File;

import com.ibm.watson.developer_cloud.speech_to_text.v1.SpeechToText;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognizeOptions;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognizeOptions.Builder;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults;

public class Sample {

    public static void main(String[] args) {
        SpeechToText service = new SpeechToText();
        service.setUsernameAndPassword("xxx", "xxx");

        //of course you have to adjust to your path here
        File audio = new File("C:\\Sprint\\workspaceNeon6\\S2T\\src\\cap047.wav");

        /*
         * The format of the audio data specified as one of the following values: [br]
         * [ul]
         * [li][code]audio/flac[/code] for Free Lossless Audio Codec (FLAC)[/li]
         * [li][code]audio/l16[/code] for Linear 16-bit Pulse-Code Modulation (PCM).[/li]
         * [li][code]audio/wav[/code] for Waveform Audio File Format (WAV)[/li]
         * [li][code]audio/ogg;codecs=opus[/code] for Ogg format files that use the opus codec[/li]
         * [/ul]
         */
        RecognizeOptions options = new Builder().contentType("audio/wav").build();
        SpeechResults transcript = service.recognize(audio,options).execute();
        System.out.println(transcript);

    }

}

notice that this is the same example code from the main github page, however, using a notation that is supposed to run and to compile, because the examples in the main page are outdated.

also, I am using the wave file from

https://github.com/watson-developer-cloud/java-sdk/blob/master/tests/src/test/resources/speech_to_text/sample1.wav

then I get the following error message

Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/watson/developer_cloud/service/WatsonService
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at Sample.main(Sample.java:11)
Caused by: java.lang.ClassNotFoundException: com.ibm.watson.developer_cloud.service.WatsonService
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 more

so OK, it seems I am missing some library, let's try another POM

        [dependency]
            [groupId]com.ibm.watson.developer_cloud[/groupId]
            [artifactId]java-sdk[/artifactId]
            [version]3.3.1[/version]
        [/dependency]

(because 3.4.0 and 3.5.0 don't work in eclipse)

Now the code compiles, but the request returns

out 20, 2016 5:59:06 PM com.ibm.watson.developer_cloud.service.WatsonService processServiceCall
SEVERE: POST https://stream.watsonplatform.net/speech-to-text/api/v1/recognize, status: 400, error: unable to transcode data stream audio/wav -] audio/x-float-array 
Exception in thread "main" com.ibm.watson.developer_cloud.service.exception.BadRequestException: unable to transcode data stream audio/wav -] audio/x-float-array 
    at com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:416)
    at com.ibm.watson.developer_cloud.service.WatsonService$1.execute(WatsonService.java:179)
    at Sample.main(Sample.java:27)

So I think I am out of tricks.

Any help is welcome.

germanattanasio commented 8 years ago

In Eclipse, you can have:

Create a Java class with a main static method like the following:

/**
 * Recognize a sample wav file and print the transcript into the console output. Make sure you are using UTF-8 to print
 * messages; otherwise, you will see question marks.
 */
public class SpeechToTextExample {

  public static void main(String[] args) {
    SpeechToText service = new SpeechToText();
    service.setUsernameAndPassword("<username>", "<password>");

    File audio = new File("sample1.wav");
    SpeechResults transcript = service.recognize(audio).execute();

    System.out.println(transcript);
  }
}

Replace the sample1.wav, <username>, and <password> with valid values and you will get a working sample.

shikida commented 8 years ago

sorry, I just had to right click on the maven project Maven->Update Maven Project->Force Update of Snapshots/Releases