eshrh / ames

Anki Media Extractor Script: Update anki cards with desktop audio and image on gnu/linux
GNU General Public License v3.0
47 stars 10 forks source link

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

Open venturiq opened 1 week ago

venturiq commented 1 week ago

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

stephen-huan commented 1 week ago

Duplicate of https://github.com/eshrh/ames/issues/14? We haven't actually fixed https://github.com/eshrh/ames/issues/14 yet, so feel free to keep the issue open...

WaddlesPlays commented 1 week ago

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: ```bash 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 } ```
venturiq commented 1 week ago

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 commented 3 days ago

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 commented 3 days ago

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
}