title: How to convert a wav audio file format (sample width) into 8 bits format?
body: <p>I am using a Python gui that records the voice and I need to set the Width format of the wav file into 8 bits. When I run the recording has nothing but noise!</p>
  <pre><code>import tkinter as tk
  import threading
  import pyaudio
  import wave
  from tkinter import *
  import tkinter.font as font
  from tkinter.filedialog import asksaveasfilename
  
  class App():
      chunk = 1024
      sample_format = pyaudio.paUInt8
      channels = 2
      fs =44100 
  
  frames = []
  
  def __init__(self, master):
      self.isrecording = False
      myFont = font.Font(weight=&quot;bold&quot;)
      self.button1 = tk.Button(audio_window, text='Record', command=self.startrecording,
                               height=2, width=20, bg='#0052cc', fg='#ffffff')
      self.button2 = tk.Button(audio_window, text='stop', command=self.stoprecording,
                               height=2, width=20, bg='#0052cc', fg='#ffffff')
      self.button1['font'] = myFont
      self.button2['font'] = myFont
      self.button1.place(x=30, y=30)
      self.button2.place(x=280, y=30)
  
  def startrecording(self):
      self.p = pyaudio.PyAudio()
      self.stream = self.p.open(format=self.sample_format, channels=self.channels,
          rate=self.fs, frames_per_buffer=self.chunk, input=True)
      self.isrecording = True
  
      print('Recording')
      t = threading.Thread(target=self.record)
      t.start()
  
  def stoprecording(self):
      self.isrecording = False
      print('recording complete')
  
      self.filename = asksaveasfilename(initialdir=&quot;/&quot;, title=&quot;Save as&quot;,
          filetypes=((&quot;audio file&quot;, &quot;*.wav&quot;), (&quot;all files&quot;, &quot;*.*&quot;)),
          defaultextension=&quot;.wav&quot;)
  
      wf = wave.open(self.filename, 'wb')
      wf.setnchannels(self.channels)
      wf.setsampwidth(self.p.get_sample_size(self.sample_format))
      wf.setframerate(self.fs)
      wf.writeframes(b''.join(self.frames))
      
  def record(self):
      while self.isrecording:
          data = self.stream.read(self.chunk)
          self.frames.append(data)
          print(&quot;does it&quot;)
  
  audio_window = tk.Tk()
  audio_window.title('recorder')
  app = App(audio_window)
  audio_window.geometry('520x120')
  audio_window.mainloop()
  </code></pre>
  <p>This is the recording GUI I used. I need the recording to be in 8 bits because I need to encrypt it later.</p>