Use
with open("filename", 'w') as outFile:
for frame in frames:
outFile.write(frame)
to concatenate all frames as byte stream into that file.
Question
I have written the AES for data encryption, my code is capable of encryption Text files while picking 32 bytes at a time...I now want to encrypt the recorded voice as well,
this is what I have done so far,
import pyaudio
import wave
import sys
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "R_Voice.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("The Voice is being Recorded........")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print (frames)
f = open("abc.txt",'w')
f.write(str(frames))
f.close()
The frames[]
consist of the Hexadecimal data of the recorded voice i wanted to write this data into a file as a string so i did this (as shown above)
f.write(str(frames))
but when I see the data in the file abc.txt
after executing the program, it is in this form, and complete data is in a single line which usually hangs my Raspberry Pi.
['7\xe47\xe4O\xe4O\xe4N\xe4N\xe4A\xe4A\xe4F\xe4F\xe4C\xe4C\xe4H\xe4H\xe4Y\x
How am i supposed to convert it to the string so that i could encrypt it ?
Solution
Use
with open("filename", 'w') as outFile:
for frame in frames:
outFile.write(frame)
to concatenate all frames as byte stream into that file.