Skip to content

Commit 9285b34

Browse files
authored
Merge pull request #363 from CodeReaper-10/audio-rec
Audio Recorder
2 parents 7df8fcd + ddb822e commit 9285b34

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ Once you are done working on your script edit this `README.md` file and add the
9999
72| QR and Barcode Scanner | Scans both QR Codes and Barcodes | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/QR%20and%20Barcode%20Scanner) |
100100
73| PDF-Delete-Pages | Deletes pages from PDF as entered by the user | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/PDF-Delete-Pages) |
101101
74| Copy to clipboard | Copies contents form a text file to your clipboard | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Copy%20to%20clipboard) |
102+
75| Audio Recorder | Records audio from system's audio input device for `n` seconds | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Audio%20Recorder) |
102103
### Good Luck and don't forget to have fun with Open Source 🚀

scripts/Audio Recorder/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## How to run
2+
1. Clone the repository
3+
```
4+
git clone [email protected]:GDSC-RCCIIT/General-Purpose-Scripts.git
5+
```
6+
2. Install the script requirements
7+
```
8+
pip install -r requirements.txt
9+
```
10+
3. Navigate to `Audio Recorder` directory
11+
```
12+
cd General-Purpose-Scripts/scripts/Audio Recorder
13+
```
14+
4. Run the script to record audio
15+
```
16+
python audio.py
17+
```

scripts/Audio Recorder/audio.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import time
2+
import sounddevice as sd
3+
import wavio as wv
4+
5+
# Sampling frequency
6+
freq = 45000
7+
8+
# Recording duration
9+
duration = int(input("Enter the duration (in seconds): "))
10+
11+
print("Recording...")
12+
# Start recorder with the given values of duration and sample frequency
13+
recording = sd.rec(int(duration * freq), samplerate=freq, channels=2)
14+
15+
# View timer and record audio for the given number of seconds
16+
while duration:
17+
mins, secs = divmod(duration, 60)
18+
timer = "{:02d}:{:02d}".format(mins, secs)
19+
print(timer, end="\r")
20+
time.sleep(1)
21+
duration -= 1
22+
23+
print("Done!")
24+
num = input("Enter a number for your file name: ")
25+
26+
# Convert the NumPy array to audio file
27+
wv.write("recording" + num + ".wav", recording, freq, sampwidth=2)
28+
29+
print("Saved file as recording" + num + ".wav in the present directory.")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sounddevice==0.4.3
2+
wavio==0.0.4

0 commit comments

Comments
 (0)