Code Monkey home page Code Monkey logo

Comments (4)

bastibe avatar bastibe commented on August 30, 2024

That really depends on your actual use case. Just call Recorder.record() repeatedly until you press your key. There is no magic to it.

with soundcard.default_microphone().recorder() as rec:
    while True:
        data = rec.record()
        if key_has_been_pressed():
            break

from soundcard.

kunaia avatar kunaia commented on August 30, 2024

yes, I have solved that problem, but sometimes it shows the following problem:
Assertion 's' failed at pulse/stream.c:1411, function pa_stream_connect_record(). Aborting.

why?

my code here:

sounds = []
while True:
    sounds.clear()
    with rec.recorder(samplerate=48000) as mic:
        while keyboard.is_pressed('r'):
            sound = mic.record()
            sounds.append(sound)

from soundcard.

bastibe avatar bastibe commented on August 30, 2024

Please post a complete, executable example, and a complete stack trace.

from soundcard.

kunaia avatar kunaia commented on August 30, 2024
import os
import numpy as np
import soundcard as snd
import keyboard as kbrd
from scipy.io.wavfile import write


rec = snd.default_microphone()
spk = snd.default_speaker()

cnt = 1
sounds = []
while True:
    sounds.clear()
    with rec.recorder(samplerate=48000) as mic:
        while kbrd.is_pressed('r'):
            sound = mic.record()
            sounds.append(sound)

    if len(sounds) > 0:
        voice = sounds[0]
        for i in range(1, len(sounds)):
            voice = np.append(voice, sounds[i], axis=0)

        voice = np.int16(voice / np.max(np.abs(voice)) * 32767)
        write('{}.wav'.format(cnt), 48000, voice)

        print('\n')
        cnt += 1

from soundcard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.