そこで、画像入力を音波出力に変換する次のコードを書きましたが、問題なく動作します。
import wave
try:
#change the file's name and format
image_file = 'image.png'
fin = open(image_file, "rb") #binary read
data = fin.read()
fin.close()
except IOError:
print("Image file %s not found" % imageFile)
raise SystemExit
#Give the name for wav file produced at run time corresponding to the input file
sound_output = wave.open('image.wav', 'w')
sound_output.setparams((2, 2, 44100, 10, 'NONE', 'not compressed'))
hex_str = bytes(data) #convert binary data to string of bytes
sound_output.writeframes(hex_str)
sound_output.close()
今、私はその出力波音を使用して、それを画像とテキストに変換したいと考えています(元の画像ではなく、出力できる画像)。ウェーブサウンドファイルを入力として受け取り、バイナリデータとして読み取る上記と同じアプローチを考えています。しかし、そのバイナリ データを画像形式 (jpg または png) およびテキストの文字列として保存する方法がわかりません。誰でも助けることができますか?