first commit

This commit is contained in:
ange committed 2025-03-04 18:23:32 +01:00
1 parent 523706e176
commit 85736f351f
9 files changed
+142

No files matched your search

+2
View File
@@ -169,3 +169,5 @@ cython_debug/
# PyPI configuration file
.pypirc
View File
Whitespace-only changes.
+13
View File
@@ -0,0 +1,13 @@
import evdev
def check_f12(event):
print("test")
if event.code == evdev.ecodes.KEY_F12:
return True # F12 key was pressed *
if __name__ == "__main__":
evdev.main()
+34
View File
@@ -0,0 +1,34 @@
# RayPonder/player.py
import pyaudio
import wave
def play_message():
filename = './messages/Cabine6.wav'
# Set chunk size of 1024 samples per data frame
chunk = 1024
print("playing")
# Open the sound file
wf = wave.open(filename, 'rb')
# Create an interface to PortAudio
p = pyaudio.PyAudio()
# Open a .Stream object to write the WAV file to
# 'output = True' indicates that the sound will be played rather than recorded
stream = p.open(format = p.get_format_from_width(wf.getsampwidth()),
channels = wf.getnchannels(),
rate = wf.getframerate(),
output = True)
# Read data in chunks
data = wf.readframes(chunk)
# Play the sound by writing the audio data to the stream
while len(data) != 0:
stream.write(data)
data = wf.readframes(chunk)
# Close and terminate the stream
stream.close()
p.terminate()
+79
View File
@@ -0,0 +1,79 @@
# RayPonder/record.py
import pyaudio
import wave
import threading
from pynput import keyboard
import time
import os
# Paramètres d'enregistrement
FORMAT = pyaudio.paInt32
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 15 * 60 # 15 minutes
temp_folder = './temp_audio/'
if not os.path.exists() or not os.path.isdir():
try:
os.mkdir(temp_folder)
except OSError:
print("impossible de créer le dossier temp_audio")
else:
print("dossier temp_audio existant")
# Création d'un objet PyAudio
p = pyaudio.PyAudio()
# Ouvrir le flux audio
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
# Variable pour stocker l'état de l'enregistrement
recording = True
def record_audio():
global recording
frames = []
while recording:
# print("recording")
# time.sleep(0.5)
data = stream.read(CHUNK)
frames.append(data)
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
def on_press(key):
global recording
if key == keyboard.Key.f12:
recording = False
return False
def main():
# Démarrer la surveillance des appuis sur les touches du clavier
listener = keyboard.Listener(on_press=on_press)
listener.start()
# Démarrer l'enregistrement
record_thread = threading.Thread(target=record_audio)
record_thread.start()
# Attendre la fin de l'enregistrement
# record_thread.join()
listener.join()
if __name__ == "__main__":
main()
Binary file not shown.
View File
Whitespace-only changes.
+12
View File
@@ -0,0 +1,12 @@
# ray-ponder.py
from RayPonder import player, record
def main():
# Jouer un fichier audio
player.play_message()
# Démarrer l'enregistrement
record.record_audio()
if __name__ == "__main__":
main()
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore