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

Recording starts but doesn't paste to Anki after ending. #15

Open
TuxEnthusiast opened this issue Oct 29, 2024 · 5 comments
Open

Recording starts but doesn't paste to Anki after ending. #15

TuxEnthusiast opened this issue Oct 29, 2024 · 5 comments

Comments

@TuxEnthusiast
Copy link

TuxEnthusiast commented Oct 29, 2024

I downloaded this script a couple of days ago and it worked perfectly. I don't really know what happened, but now it just gives me the "Recording..." notification and when I hit my bind again nothing happens. Sometimes it does end up adding the card minutes after I've ended the recording. Nothing gets printed when I enter the command into the terminal. I don't know what to do. Please help. I love this tool. Thank you.

image

image

It seems to be stuck in this loop:
image

OS: Fedora Linux 41 (KDE Plasma)KERNEL: 6.11.5-300.fc41.x86_64CPU: Intel Core i7-7700K @ 4.20GHzGPU: NVIDIA GeForce GTX 1070GPU DRIVER: NVIDIA 560.35.03RAM: 32 GB

@TuxEnthusiast TuxEnthusiast changed the title Recording starts but doesn't paste to anki after ending. Recording starts but doesn't paste to Anki after ending. Oct 30, 2024
@stephen-huan
Copy link
Collaborator

Duplicate of #14? We haven't actually fixed #14 yet, so feel free to keep the issue open...

@WaddlesPlays
Copy link

I ran into this issue today, and using some insight from #14 I was able to get a working config by replacing the recording function with pw-record -P '{ stream.capture.sink=true }' "$audio_file" and removing a few things that didn't seem to be needed anymore from record_start and record_end. It does rely on pipewire, and may not conform to any given setup, but it should be a solid start!

Here is the config:
record_function() {
    local -r audio_file="$1"
    pw-record -P '{ stream.capture.sink=true }' "$audio_file" 1> /dev/null &
}

record_start() {
    # begin recording audio.
    local -r audio_file="$(mktemp \
                               "/tmp/pipewire-recording.XXXXXX.$AUDIO_FORMAT")"
    echo "$audio_file" > "$recording_toggle"

    record_function "$audio_file"
    echo "$!" >> "$recording_toggle"

    current_time >> "$recording_toggle"

    notify_record_start
}

record_end() {
    # end recording.
    local -r audio_file="$(sed -n "1p" "$recording_toggle")"
    local -r pid="$(sed -n "2p" "$recording_toggle")"
    local -r start_time="$(sed -n "3p" "$recording_toggle")"
    local -r duration="$(($(current_time) - start_time))"

    if [ "$duration" -le "$MINIMUM_DURATION" ]; then
        sleep "$((MINIMUM_DURATION - duration))e-3"
    fi

    rm "$recording_toggle"
    kill -15 "$pid"

    while [ "$(du "$audio_file" | awk '{ print $1 }')" -eq 0 ]; do
        true
    done

    store_file "${audio_file}"
    update_sound "$(basename -- "$audio_file")"

    notify_record_stop
}

@TuxEnthusiast
Copy link
Author

I ran into this issue today, and using some insight from #14 I was able to get a working config by replacing the recording function with pw-record -P '{ stream.capture.sink=true }' "$audio_file" and removing a few things that didn't seem to be needed anymore from record_start and record_end. It does rely on pipewire, and may not conform to any given setup, but it should be a solid start!
Here is the config:

This actually fixed it for me. Thank you!

@WilsonNet
Copy link

WilsonNet commented Nov 5, 2024

Oh we have very different setups and you also had the same problem as me, maybe it is an ffmpeg or kernel issue?

Anyway, my setup here if anyone is interested to dive further on the issue.

OS: Arch Linux x86_64
Host: Redmi Book Pro 14 2022
Kernel: Linux 6.11.5-arch1-1
CPU: AMD Ryzen 7 6800H (16) @ 4.79 GHz
GPU: AMD Radeon 680M [Integrated]
Memory: 8.93 GiB / 14.82 GiB (60%)
Window Manager: AWM (xorg)
Pipewire

@WilsonNet
Copy link

WilsonNet commented Nov 5, 2024

My version with the pw-record command (feel free to create a PR with this if anybody wants, I'm too lazy for that

record_function() {
    local -r audio_file="$1"
    # We need the & at the end otherwise it hangs in the pw-record
    pw-record -P '{ stream.capture.sink=true }' "$audio_file" &
}

record_start() {
    # begin recording audio.
    local -r audio_file="$(mktemp \
                               "/tmp/ffmpeg-recording.XXXXXX.$AUDIO_FORMAT")"
    echo "$audio_file" >"$recording_toggle"

    record_function "$audio_file"
    echo "$!" >> "$recording_toggle"

    current_time >> "$recording_toggle"

    notify_record_start
}

record_end() {
    local -r audio_file="$(sed -n "1p" "$recording_toggle")"
    local -r pid="$(sed -n "2p" "$recording_toggle")"
    local -r start_time="$(sed -n "3p" "$recording_toggle")"
    local -r duration="$(($(current_time) - start_time))"

    echo "The pid is: ${pid}"
    if [ "$duration" -le "$MINIMUM_DURATION" ]; then
        sleep "$((MINIMUM_DURATION - duration))e-3"
    fi

    rm "$recording_toggle"
    kill -15 "$pid"

    wait "$pid" || true

    while [ "$(du "$audio_file" | awk '{ print $1 }')" -eq 0 ]; do
        true
    done

    store_file "${audio_file}"
    update_sound "$(basename -- "$audio_file")"

    notify_record_stop
}

record() {
    # this section is a heavily modified version of the linux audio
    # script written by salamander on qm's animecards.
    recording_toggle="/tmp/ffmpeg-recording-audio"

    if [[ ! -f /tmp/ffmpeg-recording-audio ]]; then
        record_start
    else
        record_end
    fi
}

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

4 participants