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

Troubles with setup blackhole #7

Open
mesteruh opened this issue Sep 8, 2024 · 1 comment
Open

Troubles with setup blackhole #7

mesteruh opened this issue Sep 8, 2024 · 1 comment

Comments

@mesteruh
Copy link

mesteruh commented Sep 8, 2024

I setuped blackhole
image

when try to save wav - its empty. What i doing wrong?

@mesteruh
Copy link
Author

mesteruh commented Sep 8, 2024

import sounddevice as sd
import soundfile as sf
import numpy as np

# Параметры записи
SAMPLE_RATE = 44100  # Частота дискретизации
DURATION = 10  # Продолжительность записи в секундах
OUTPUT_FILE_NAME = "output.wav"  # Имя выходного файла

def find_blackhole_device_id():
    """
    Ищет устройство BlackHole и возвращает его ID, если оно найдено.
    """
    devices = sd.query_devices()
    for device_id, device in enumerate(devices):
        if "BlackHole" in device["name"]:
            return device_id
    return None

def record_audio():
    # Найдем устройство BlackHole
    device_id = find_blackhole_device_id()
    
    if device_id is None:
        print("BlackHole device not found!")
        return

    print(f"Using BlackHole device with ID {device_id}")

    print("Recording...")
    # Запись аудио с BlackHole устройства
    audio_data = sd.rec(int(SAMPLE_RATE * DURATION), samplerate=SAMPLE_RATE, channels=2, dtype='float64', device=device_id)
    sd.wait()  # Ожидание окончания записи
    print("Recording finished")
    
    # Сохранение в файл
    sf.write(OUTPUT_FILE_NAME, audio_data, SAMPLE_RATE)
    print(f"Audio saved to {OUTPUT_FILE_NAME}")

if __name__ == "__main__":
    record_audio()

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

1 participant