{"id":21803143,"url":"https://github.com/litongjava/whipser-cpp-java","last_synced_at":"2025-10-07T23:30:57.073Z","repository":{"id":204850751,"uuid":"712807838","full_name":"litongjava/whipser-cpp-java","owner":"litongjava","description":"Java JNI Bindings for Whisper","archived":false,"fork":false,"pushed_at":"2024-10-14T19:01:44.000Z","size":271,"stargazers_count":5,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-27T11:45:18.947Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/litongjava.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-01T08:36:38.000Z","updated_at":"2024-11-13T15:14:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"d1351c07-fbe5-43e5-a9db-6941aa3487c6","html_url":"https://github.com/litongjava/whipser-cpp-java","commit_stats":null,"previous_names":["litongjava/whipser-cpp-java"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/litongjava%2Fwhipser-cpp-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/litongjava%2Fwhipser-cpp-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/litongjava%2Fwhipser-cpp-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/litongjava%2Fwhipser-cpp-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/litongjava","download_url":"https://codeload.github.com/litongjava/whipser-cpp-java/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235661855,"owners_count":19025609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-27T11:38:58.660Z","updated_at":"2025-10-07T23:30:51.698Z","avatar_url":"https://github.com/litongjava.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Java JNI Bindings for Whisper\n[English](README.md)|[中文](readme_cn.md)  \nThis package offers Java JNI bindings for `whisper.cpp`. The following platforms have been successfully tested:\n\n- ~~Darwin (OS X) 12.6 on x64_64~~\n- Ubuntu on x86_64\n- Windows on x86_64\n\nThe primary \"low-level\" bindings can be found in `WhisperCppJnaLibrary`. A basic example of its usage is:\n\nJNA will try to load the `whispercpp` shared library from the following paths:\n\n- `jna.library.path`\n- `jna.platform.library`\n- `~/Library/Frameworks`\n- `/Library/Frameworks`\n- `/System/Library/Frameworks`\n- classpath\n\n## Import\nmaven\n```\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.litongjava\u003c/groupId\u003e\n    \u003cartifactId\u003ewhisper-cpp-java\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\ngradle\n```\nimplementation \"com.litongjava:whisper-cpp-java:1.0.0\"\n```\n## Testing\n\n### Loading the Model\n\n1. Download the `whisper` library or compile it to generate the required library files. Source: [Whisper GitHub Repository](https://github.com/ggerganov/whisper.cpp)\n2. Place the `whisper` library in the appropriate [JNA library path](https://java-native-access.github.io/jna/4.2.1/com/sun/jna/NativeLibrary.html). Note: For Windows users, the `.dll` file is already included in the `.jar`, but can be updated if needed:\n\n```bash\nsrc\\main\\resources\\win32-x86-64\\whisper.dll\n```\n\n```java\npackage com.litongjava.whipser.cpp.java;\n\nimport static org.junit.jupiter.api.Assertions.assertTrue;\n\nimport org.junit.jupiter.api.Test;\n\nclass WhisperJnaLibraryTest {\n\n  @Test\n  void testWhisperPrint_system_info() {\n    String systemInfo = WhisperCppJnaLibrary.instance.whisper_print_system_info();\n    // eg: \"AVX = 1 | AVX2 = 1 | AVX512 = 0 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0\n    // | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | VSX = 0 | COREML = 0 | \"\n    System.out.println(\"System info: \" + systemInfo);\n    assertTrue(systemInfo.length() \u003e 10);\n  }\n}\n```\n\n### Sample Test\n\n1. Download the model from:\n   - [Hugging Face Model](https://huggingface.co/ggerganov/whisper.cpp)\n   - [GGML Model](https://ggml.ggerganov.com)\n  \n2. Store the model in `~/.cache/whisper/`. By default, models are sourced from this location and typically have the naming convention \"ggml-${name}.bin\".\n3. Download sample files like [jfk.wav](https://github.com/ggerganov/whisper.cpp/blob/master/samples/jfk.wav) and place them in the `samples` folder.\n\n```java\npackage com.litongjava.whipser.cpp.java;\n\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.util.List;\n\nimport javax.sound.sampled.AudioInputStream;\nimport javax.sound.sampled.AudioSystem;\nimport javax.sound.sampled.UnsupportedAudioFileException;\n\nimport com.litongjava.whipser.cpp.java.bean.WhisperSegment;\nimport com.litongjava.whipser.cpp.java.callbacks.WhisperProgressCallback;\nimport com.litongjava.whipser.cpp.java.params.CBool;\nimport com.litongjava.whipser.cpp.java.params.WhisperFullParams;\nimport com.litongjava.whipser.cpp.java.params.WhisperSamplingStrategy;\n\npublic class WhisperCppDemo {\n\n  private static WhisperCpp whisper = new WhisperCpp();\n  private static boolean modelInitialised = false;\n\n  public static void main(String[] args) {\n\n    // By default, models are loaded from ~/.cache/whisper/ and are usually named \"ggml-${name}.bin\"\n    // or you can provide the absolute path to the model file.\n    // String modelName = \"ggml-base.en.bin\"; // load ggml-base.en.bin\n    String modelName = \"ggml-large-v3-turbo.bin\"; // load ggml-large-v3-turbo.bin\n    try {\n      whisper.initContext(modelName);\n      modelInitialised = true;\n    } catch (FileNotFoundException ex) {\n      ex.printStackTrace();\n      System.out.println(\"Model \" + modelName + \" not found\");\n      return;\n    }\n    if (!modelInitialised) {\n      System.out.println(\"Model not initialised, skipping test\");\n      return;\n    }\n\n    WhisperFullParams params = whisper.getFullDefaultParams(WhisperSamplingStrategy.WHISPER_SAMPLING_BEAM_SEARCH);\n    WhisperProgressCallback callback = (ctx, state, progress, user_data) -\u003e System.out.println(\"progress: \" + progress);\n\n    params.setProgressCallback(callback);\n    params.print_progress = CBool.FALSE;\n\n    // Given\n    File file = new File(System.getProperty(\"user.dir\"), \"/samples/jfk.wav\");\n\n    List\u003cWhisperSegment\u003e segments = transcribe(params, file);\n    System.out.println(segments.size());\n\n    for (WhisperSegment segment : segments) {\n      System.out.println(segment);\n    }\n  }\n\n  private static List\u003cWhisperSegment\u003e transcribe(WhisperFullParams params, File file) {\n    try (AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);) {\n      byte[] b = new byte[audioInputStream.available()];\n      float[] floats = new float[b.length / 2];\n      audioInputStream.read(b);\n\n      for (int i = 0, j = 0; i \u003c b.length; i += 2, j++) {\n        int intSample = (int) (b[i + 1]) \u003c\u003c 8 | (int) (b[i]) \u0026 0xFF;\n        floats[j] = intSample / 32767.0f;\n      }\n\n      return whisper.fullTranscribeWithTime(params, floats);\n    } catch (IOException e) {\n      e.printStackTrace();\n\n    } catch (UnsupportedAudioFileException e) {\n      e.printStackTrace();\n    }\n    return null;\n  }\n}\n\n```\n\n**Output:**\n```\n[0 --\u003e 1100]: And so, my fellow Americans, ask not what your country can do for you—ask what you can do for your country.\n```\nNote: Here, 1100 represents milliseconds divided by 10.\n\n## Building\n\nTo build, ensure you have JDK 8 or higher installed. You can run the tests with the following commands:\n\n```bash\ngit clone https://github.com/litongjava/whisper-cpp-java.git\ncd whisper-cpp-java\nmvn install -DskipTests -Dgpg.skip\n```\n## Java Whisper Cpp Server\n[https://github.com/litongjava/ai-server](https://github.com/litongjava/ai-server)\n\n## License\n\nThe licensing for these Java bindings matches that of the entire `whisper.cpp` project, which is under the MIT License. Please refer to the [`LICENSE`](https://github.com/ggerganov/whisper.cpp/blob/master/LICENSE) file for comprehensive details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flitongjava%2Fwhipser-cpp-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flitongjava%2Fwhipser-cpp-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flitongjava%2Fwhipser-cpp-java/lists"}