Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve WAV sample rate and number of channels #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions record_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def choose_rtx_output():
return int(microphone_choice)


def record(length=10, user_output_name="file", mic_input='',bitrate_input=48000):
def record(length=10, user_output_name="file", mic_input='',
sample_rate=48000, channels=2):
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = bitrate_input
CHANNELS = channels
RATE = sample_rate
CHUNK = 1024
RECORD_SECONDS = length

Expand All @@ -71,7 +72,7 @@ def record(length=10, user_output_name="file", mic_input='',bitrate_input=48000)
format=FORMAT,
channels=CHANNELS,
input_device_index=mic_input,
rate=RATE,
rate=sample_rate,
input=True,
frames_per_buffer=CHUNK,
)
Expand All @@ -90,9 +91,9 @@ def record(length=10, user_output_name="file", mic_input='',bitrate_input=48000)
pyaudio_inst.terminate()

waveFile = wave.open(WAVE_OUTPUT_FILENAME, "wb")
waveFile.setnchannels(CHANNELS)
waveFile.setnchannels(channels)
waveFile.setsampwidth(pyaudio_inst.get_sample_size(FORMAT))
waveFile.setframerate(RATE)
waveFile.setframerate(sample_rate)
waveFile.writeframes(b"".join(frames))
waveFile.close()
print("Complete!\n")
Expand Down
16 changes: 11 additions & 5 deletions rtx-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from mutagen.mp3 import MP3
from mutagen.flac import FLAC
from mutagen.wave import WAVE

from input_handle import *
from record_handle import *
Expand Down Expand Up @@ -34,8 +35,8 @@ def main(argv):
codec = "MP3"
convert = True
elif "wav" in input_file_extension.lower():
codec = "MP3"
convert = True
codec = "WAVE"
convert = False

# Convert the input file to MP3 if it is not already
if convert == True:
Expand Down Expand Up @@ -64,15 +65,19 @@ def main(argv):
input_track = MP3(input_song_path)
elif codec == "FLAC":
input_track = FLAC(input_song_path)
elif codec == "WAVE":
input_track = WAVE(input_song_path)

length_of_input_song = int(input_track.info.length)
hours, mins, seconds = convertTime(length_of_input_song)
bitrate_of_input_song = int(input_track.info.sample_rate)
bitrate_of_input_song = int(input_track.info.bitrate)
sample_rate_input_song = int(input_track.info.sample_rate)
channels = int(input_track.info.channels)

# Print some info about the song to the console
print("\nNow Processing: " + input_song_path + "\n")
print("SampleRat: " + str(bitrate_of_input_song))
print("SampleRate: " + str(sample_rate_input_song))
print("Bitrate: " + str(bitrate_of_input_song))
print('Duration: %s:%s:%s' % (hours, mins, seconds))
print("Playbacktime is in Realtime, this tool tunnels the audio to the RTX Voice Input")
print("Endtime: " + add_time(hours, mins, seconds))
Expand All @@ -82,7 +87,8 @@ def main(argv):
length_of_input_song+addTimepaddding,
export_song_path,
mic_input,
bitrate_of_input_song
sample_rate_input_song,
channels=channels
)
mixer.music.stop() # Stop it
mixer.quit() # Quit it
Expand Down