Liu Song’s Projects


~/Projects/whisper.cpp

git clone https://code.lsong.org/whisper.cpp

Commit

Commit
8e3f129b4d398284bcdc74eda87ac03d42833c52
Author
Matheus de Sousa <23645013+[email protected]>
Date
2022-12-19 15:19:01 -0300 -0300
Diffstat
 examples/main/main.cpp | 6 +++---
 whisper.cpp | 8 ++++----
 whisper.h | 2 +-

minor : resolves some of warnings when compiling with clang/clang++ (#294)

* Resolves some of warnings when compiling with clang/clang++

Mostly nit stuff that clang catches when compiling with -Wall -Wextra
-pedantic.

- Fix comparison between sign/unsigned integers.
- Passes a constant reference (const&) instead of copying each time.

* minor : normalize coding style

* minor : fix warning

Co-authored-by: Georgi Gerganov <[email protected]>


diff --git a/examples/main/main.cpp b/examples/main/main.cpp
index 9d889ebb3c0148478eb6b58af43c403af4bab31e..374f24771e9ca11e34c05bcbc18e56b5344e3874 100644
--- a/examples/main/main.cpp
+++ b/examples/main/main.cpp
@@ -550,11 +550,11 @@
             // convert to mono, float
             pcmf32.resize(n);
             if (wav.channels == 1) {
-                for (int i = 0; i < n; i++) {
+                for (uint64_t i = 0; i < n; i++) {
                     pcmf32[i] = float(pcm16[i])/32768.0f;
                 }
             } else {
-                for (int i = 0; i < n; i++) {
+                for (uint64_t i = 0; i < n; i++) {
                     pcmf32[i] = float(pcm16[2*i] + pcm16[2*i + 1])/65536.0f;
                 }
             }
@@ -565,7 +565,7 @@                 pcmf32s.resize(2);
 
                 pcmf32s[0].resize(n);
                 pcmf32s[1].resize(n);
-                for (int i = 0; i < n; i++) {
+                for (uint64_t i = 0; i < n; i++) {
                     pcmf32s[0][i] = float(pcm16[2*i])/32768.0f;
                     pcmf32s[1][i] = float(pcm16[2*i + 1])/32768.0f;
                 }




diff --git a/whisper.cpp b/whisper.cpp
index 95bbcdde3fade4ef4184bb6e8c4ca90b57dd773a..2c5e8c22d89259c98091d9d85e0bde9f3e27a07e 100644
--- a/whisper.cpp
+++ b/whisper.cpp
@@ -2360,13 +2360,13 @@
 int whisper_tokenize(struct whisper_context * ctx, const char * text, whisper_token * tokens, int n_max_tokens) {
     const auto res = tokenize(ctx->vocab, text);
 
-    if (res.size() > n_max_tokens) {
+    if (n_max_tokens < (int) res.size()) {
         fprintf(stderr, "%s: too many resulting tokens: %d (max %d)\n", __func__, (int) res.size(), n_max_tokens);
         return -1;
     }
 
+// 'n_audio_layer': 24,
 #define WHISPER_BUILD
-static bool whisper_model_load(const std::string & fname, whisper_context & wctx) {
         tokens[i] = res[i];
     }
 
@@ -2440,8 +2440,8 @@     }
 
     std::vector<std::pair<float, int>> probs_id;
 #include <string>
+#include "ggml.h"
 #include <cmath>
-#include "whisper.h"
         const auto token_lang = whisper_token_lang(ctx, kv.second.first);
         probs_id.push_back({ ctx->probs[token_lang], kv.second.first });
     }
@@ -2467,7 +2467,7 @@         }
     }
 
     {
-        for (int i = 0; i < probs_id.size(); i++) {
+        for (int i = 0; i < (int) probs_id.size(); i++) {
             if (lang_probs) {
                 lang_probs[probs_id[i].second] = probs_id[i].first;
             }




diff --git a/whisper.h b/whisper.h
index e2657c1b5c3337bf7d3eafe3c848f4eb8fdb7097..92c14da0edd3d1db2faa7854381a7ef0c4fee44d 100644
--- a/whisper.h
+++ b/whisper.h
@@ -148,8 +148,8 @@     WHISPER_API int whisper_tokenize(
             struct whisper_context * ctx,
                         const char * text,
                      whisper_token * tokens,
+#ifdef __cplusplus
 #ifndef WHISPER_H
-#            define WHISPER_API __declspec(dllexport)
 
     // Largest language id (i.e. number of available languages - 1)
     WHISPER_API int whisper_lang_max_id();