Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to suppress stdout logging #1448

Open
danroot opened this issue Nov 7, 2023 · 4 comments
Open

How to suppress stdout logging #1448

danroot opened this issue Nov 7, 2023 · 4 comments

Comments

@danroot
Copy link

danroot commented Nov 7, 2023

I am using a library that wraps whisper.cpp (https://github.com/sandrohanea/whisper.net) to write a cross-platform console application. I would like to not see whisper_init_state log messages in the console app. Is there a flag or some other way to suppress logging?

@jmalfara
Copy link

jmalfara commented Nov 7, 2023

Do you want to suppress all the logging? There are options in the whisper params to disable the print outs during transcriptions. You can find them in the code whisper.cpp. Don't see any specific flags for the whisper_init_state. For now you could just comment it out in whisper.cpp before you build

@danroot
Copy link
Author

danroot commented Nov 7, 2023

Yes, I want to suppress or redirect all logging. it looks like whisper_set_log_callback(nil) would do that?

@jmalfara
Copy link

jmalfara commented Nov 7, 2023

whisper_set_log_callback(nil) will probably cause NPEs when log(..) is invoked. Probably best to either pass an empty function or add a boolean flag into whisper_default_log. I'm seeing some other printf or equivalents outside of that callback so there may be some more that needs to be flagged.

You can test by commenting out the print in

static void whisper_default_log(const char * text) {
    fprintf(stderr, "%s", text);
}

and see what is still printed in the console

@contractorwolf
Copy link
Contributor

I went in and commented out a bunch of of the WHISPER_LOG_INFO() out in the whisper.cpp file and some fprintf() in the main.cpp to eliminate all the logging noise (and then rebuilt with "make -j"). Also wrote a python app that takes advantage of the speed of the c++ version but allows me to pass a WAV file to it and get just the text back:

I was having similar trouble as you guys so I looked for a slightly different way. This is the file I am using now:

my stt_wav.py file:

import subprocess
import sys

# Command and its arguments
command = "./whisper.cpp/main"
model = "-m ./whisper.cpp/models/ggml-base.en.bin"
file_path = "-f " + sys.argv[1]  # Get the first parameter as the wav file path

# Combine into a single command
full_command = f"{command} {model} {file_path}"

# Execute the command and capture the output
process = subprocess.Popen(full_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()

if not bool(error.decode('utf-8').strip()): 
    # The output variable contains the command's standard output
    decoded_str = output.decode('utf-8').strip()
    processed_str = decoded_str.replace('[BLANK_AUDIO]', '').strip()
    print("Output:", processed_str)    
else: 
    # The error variable contains the command's standard error
    print("Error:", error.decode('utf-8'))

and I execute it like this:

python stt_wav.py "./audio/wake_word_detected16k.wav"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants