fill recorder with pause functionality now added

main
Rob Canning 2024-03-06 13:08:40 +01:00
parent 3053079051
commit 434f10dfdc
2 changed files with 103 additions and 95 deletions

View File

@ -89,6 +89,7 @@ def select_specific_track(conn, episode_number, episode_duration):
return r
def choose_a_track(conn, episode_number, choice ):
# random or specific file depending on value of "choice" argument
print("adding a track")
global episode_duration
global track_count
@ -100,17 +101,13 @@ def choose_a_track(conn, episode_number, choice ):
cursor = conn.cursor()
if choice == 0:
if choice == 0: # randomly select from database
cursor.execute("SELECT * FROM MUSIC_LIBRARY ORDER BY RANDOM() LIMIT 1 ;")
r = cursor.fetchone() # FETCH ONE RANDOM TRACK FROM THE DATABASE
print(r)
else:
else: # select a specific file from db via GUI
r = select_specific_track(conn, episode_number, episode_duration)
# TODO lookup path and get complete db record
#name= fd.askopenfilename()
#print(name)
song = str(r[9])
track_label = str(r[1])
track_album = str(r[2])
@ -140,7 +137,7 @@ def choose_a_track(conn, episode_number, choice ):
#artist_abreviated.append(art)
#print(artist_abreviated)
if not track_year: # where missing metadata give a dummy value
track_year = "0000"
track_year = "0000" # TODO fixme
e = Table('EPISODES')
track_number = '{:0>2}'.format(track_count)
@ -270,8 +267,6 @@ def playlist_replace_track(conn, episode_number, episode_duration):
# get the new episode time
cursor.execute('SELECT SUM(trackdur) FROM EPISODES WHERE EPISODE=? ', [episode_number])
episode_duration = cursor.fetchone()[0]
modify_playlist(conn, episode_number, episode_duration)

View File

@ -72,7 +72,7 @@ episode_duration = 10
archive = []
# sqlite database connection
conn = sqlite3.connect("database/show.db")
conn = sqlite3.connect("database/uho_music.db")
fill_path = "archive/e/{0}/audio_fills".format(episode_number)
if not os.path.exists(fill_path):
@ -82,13 +82,59 @@ if not os.path.exists(fill_path):
#TODO scrape artist bio from bandcamp?
#TODO GET VARIATION PROMPT
def get_playlist_for_fill_recording(conn, episode_number, episode_duration):
def record_fill(episode_number):
cursor = conn.cursor()
cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=? ORDER BY track_number ASC', [episode_number])
preview = cursor.fetchall()
num = input("Which TRACK # to record fill for: ")
for i in preview[int(num)-1:int(num)]:
print('''
POD TRACK#: {0}
TRACK: {2}
ARTIST: {3}
ALBUM: {1}
YEAR: {5}
LABEL: [{6}]
DURATION: {4}
GENRE: {8}
PATH:
{9}
COMMENT: {7}
'''\
.format('{:0>2}'.format(i[2]), i[4], i[5], i[6],\
i[7],i[9], i[11], i[12], i[8], i[10] ) )
in_or_out = input("hit 0 to record intro or 1 to record outro: ")
if in_or_out == "0":
the_file = "archive/e/{0}/audio_fills/{1}_in.wav".format(episode_number, num)
elif in_or_out == "1":
the_file = "archive/e/{0}/audio_fills/{1}_out.wav".format(episode_number, num)
else:
print("please select 0 or 1 (outro or intro).........")
print(the_file)
r = recorder(the_file)
p = player(the_file)
l = listener(r, p)
#os.system("clear")
print('............................Hold ctrl to record, press p to playback, press q to quit')
l.start() #keyboard listener is a thread so we start it here
l.join() #wait for the tread to terminate so the program doesn't instantly close
get_playlist_for_fill_recording(conn, episode_number)
def get_playlist_for_fill_recording(conn, episode_number):
cursor = conn.cursor()
cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=? ORDER BY track_number ASC', [episode_number])
preview = cursor.fetchall()
cursor.execute('SELECT SUM(trackdur) FROM EPISODES WHERE EPISODE=? ', [episode_number])
episode_duration = cursor.fetchone()[0]
#episode_duration = cursor.fetchone()[0]
# os.system("clear")
print("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
@ -100,74 +146,9 @@ def get_playlist_for_fill_recording(conn, episode_number, episode_duration):
print('| {0} | {3} ||| {2} ||| {1} ||| {5} ||| [{6}] ||| {4} |||\n'\
.format('{:0>2}'.format(i[2]), i[4], i[5], i[6],\
timedelta(seconds=round(i[7])), i[9], i[11] ) )
print(">> SELECT AN OPTION: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
user_input = input('''
[l]isten to track
[r]ecord voice fill
>>>>>>>>>>>>>>>>>>>>>>>>>>> OR PRESS ENTER TO PROCEED................... : ''')
if user_input == 'l':
playlist_preview_track(conn, episode_number, episode_duration)
elif user_input == "r":
if fill == "out":
num = input("Which TRACK # to record OUTRO fill for : ")
the_file = "archive/e/{0}/audio_fills/{1}_out.wav".format(episode_number, num)
elif fill == "in":
num = input("Which TRACK # to record INTRO fill for : ")
the_file = "archive/e/{0}/audio_fills/{1}_in.wav".format(episode_number, num)
else:
print("must speficy in or out")
print(the_file)
r = recorder(the_file)
p = player(the_file)
l = listener(r, p)
#os.system("clear")
for i in preview[int(num)-1:int(num)]:
print('''
POD TRACK#: {0}
TRACK: {2}
ARTIST: {3}
ALBUM: {1}
YEAR: {5}
LABEL: [{6}]
DURATION: {4}
GENRE: {8}
PATH:
{9}
COMMENT: {7}
'''\
.format('{:0>2}'.format(i[2]), i[4], i[5], i[6],\
timedelta(seconds=round(i[7])), i[9], i[11], i[12], i[8], i[10] ) )
print('............................Hold ctrl to record, press p to playback, press q to quit')
l.start() #keyboard listener is a thread so we start it here
l.join() #wait for the tread to terminate so the program doesn't instantly close
record_fill(episode_number)
# todo implement a check box TUI showing track fills completed
get_playlist_for_fill_recording(conn, episode_number, 10)
else:
get_playlist_for_fill_recording(conn, episode_number, 10)
class player:
def __init__(self, wavfile):
self.wavfile = wavfile
@ -183,8 +164,8 @@ class player:
with wave.open(self.wavfile, 'rb') as wf:
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
input_device_index=4,
output_device_index=4,
input_device_index=13,
output_device_index=13,
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
@ -235,8 +216,8 @@ class recorder:
return (in_data, pyaudio.paContinue)
self.stream = self.p.open(format = self.dataformat,
input_device_index=4,
output_device_index=4,
input_device_index=13,
output_device_index=13,
channels = self.channels,
rate = self.rate,
input = True,
@ -254,6 +235,27 @@ class recorder:
self.recording = False
print('recording finished',end='')
def pause(self):
if self.recording:
self.stream.stop_stream()
#self.stream.close()
#self.wf.close()
#self.recording = False
print('recording paused',end='')
def resume(self):
if self.recording:
self.stream.start_stream()
#self.stream.close()
#self.wf.close()
#self.recording = False
print('recording paused',end='')
class listener(keyboard.Listener):
def __init__(self, recorder, player):
@ -266,12 +268,23 @@ class listener(keyboard.Listener):
pass
elif isinstance(key, keyboard.Key): #special key event
if key.ctrl and self.player.playing == 0:
#print("if ctrl")
self.recorder.start()
elif isinstance(key, keyboard.KeyCode): #alphanumeric key event
if key.char == 'o': #press p to puase
if self.recorder.recording:
self.recorder.pause()
if key.char == 'i': #press p to puaseif key.char == 'o': #press p to puase
if self.recorder.recording:
self.recorder.pause()
if self.recorder.recording:
self.recorder.resume()
if key.char == 'q': #press q to quit
if self.recorder.recording:
if self.recorder.recording:
self.recorder.stop()
return False #this is how you stop the listener thread
return False #this is how you stop the listener thread
if key.char == 'p' and not self.recorder.recording:
self.player.start()
@ -279,16 +292,16 @@ class listener(keyboard.Listener):
if key is None: #unknown event
pass
elif isinstance(key, keyboard.Key): #special key event
if key.ctrl:
self.recorder.stop()
elif isinstance(key, keyboard.KeyCode): #alphanumeric key event
pass
#if key.ctrl:
# self.recorder.pause()
elif isinstance(key, keyboard.KeyCode): #alphanumeric key event
if key.char == "z": # key z release stops recording
self.recorder.stop()
#pass
if __name__ == '__main__':
get_playlist_for_fill_recording(conn, episode_number, 10)
get_playlist_for_fill_recording(conn, episode_number)