Comments (4)
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.
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.
Please post a complete, executable example, and a complete stack trace.
from soundcard.
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)
- Problems with the "fuzzy matcher" in get_microphone() HOT 1
- Watch for moved streams? HOT 1
- Decode error in _CoreAudio.CFString_to_str HOT 2
- feature request - ability to add virtual audio channels. HOT 1
- Why won't it save my audio when I use this with SoundFile? HOT 4
- OSError: ctypes.util.find_library() did not manage to locate a library called 'harfbuzz' please help in windows HOT 2
- Does anyone know how to make this work? HOT 1
- Wav file is empty after recording is saved to file HOT 5
- how to end playback in advance? HOT 2
- Need help with settings HOT 6
- MacOS: Empty result for all_speakers/all_microphones HOT 28
- Record audio unlimited HOT 6
- get mac audio output level HOT 1
- Queation: Is that possible to record based on a button click? HOT 1
- Data loss while recording HOT 4
- Cannot record sound with loopback if silence at start HOT 10
- loopback record audio from speaker return zero array HOT 5
- Problem with the player HOT 1
- how to get non numpy "raw" mono data from the record() method HOT 2
- pluseaudio.py line 3 `import collections` set --> `import collections.abc as collections` HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from soundcard.