def _play(soundfile): if platform.startswith('win'): from winsound import PlaySound, SND_FILENAME, SND_ASYNC PlaySound(soundfile, SND_FILENAME|SND_ASYNC) elif 'linux' in platform: from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(soundfile,'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp = None try: dsp = ossOpen('/dev/dsp','w') dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) except IOError: print _("Audio device is busy.") finally: if dsp: dsp.close()
def _playsoundNix(sound, block = True): ''' Utilizes ossaudiodev. Untested. Probably works with all version of Linux with Python 2.3 or newer. Inspired by, and more or less copied from, Bill Dandreta's post on this mailing list (since deleted, so I link to a web archive instead): https://web.archive.org/web/20080218155209/http://mail.python.org/pipermail/python-list/2004-October/288905.html ''' import ossaudiodev from sys import byteorder from wave import open as waveOpen, AFMT_S16_LE, AFMT_S16_BE with waveOpen(sound, 'rb') as sound: channelCount, sampleWidth, framerate, frameCount, compressionType, compressionName = sound.getparams() try: from ossaudiodev import AFMT_S16_NE except ImportError: if 'little' in byteorder.lower(): AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE data = sound.readframes(frameCount) speaker = ossaudiodev.open('/dev/dsp', 'w') speaker.setparameters(AFMT_S16_NE, channelCount, framerate) speaker.write(data) speaker.close()
def main(args: Sequence[str]) -> None: wavFileName = args[0] with waveOpen(wavFileName) as f: nChannels = f.getnchannels() assert nChannels == 1 sampWidth = f.getsampwidth() assert sampWidth == 2 frameRate = f.getframerate() assert frameRate == 44100 nFrames = f.getnframes() assert nFrames assert f.getcomptype() == 'NONE' assert len(f.readframes(nFrames)) == nFrames * nChannels * sampWidth length = float(nFrames) / frameRate m = FILENAME_PATTERN.match(wavFileName) assert m # Should always match srtFileName = f'{m.group(1)}.srt' realTime = datetime.strptime(wavFileName, WAV_FILENAME_FORMAT) realTime += timedelta( hours=2 ) # На «Обитаемых островах» ноутбук был настроен на неверную таймзону fileTime = datetime(1, 1, 1) # We don't actually use the date part srtEnd = fileTime + timedelta(seconds=length) maxN = int(length + 1 if length % 1 else length) with open( srtFileName, 'w', encoding='utf-8' ) as f: # Adobe Premiere only understands Russian in UTF-8 encoding for n in range(1, maxN + 1): nextTime = fileTime + SECOND f.write( f"{n}\n{srtFormat(fileTime)} --> {srtFormat(min(srtEnd, nextTime))}\n{displayFormat(realTime)}\n\n" ) realTime += SECOND fileTime = nextTime
def playSound(sound_file): if isWindows(): import winsound winsound.PlaySound(sound_file, winsound.SND_FILENAME) elif isLinux(): import subprocess import errno try: FNULL = open('/dev/null', 'w') subprocess.Popen(['aplay', '-q', sound_file], stdin=FNULL, stdout=FNULL, stderr=FNULL) except OSError, e: if e.errno == errno.ENOENT: from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(sound_file, 'rb') (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp = ossOpen('/dev/dsp', 'w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
def playSound2(self, file): # Thanks to Bill Dandreta: # http://mail.python.org/pipermail/python-list/2004-October/288905.html if sys.platform.startswith('win'): from winsound import PlaySound, SND_FILENAME, SND_ASYNC PlaySound(file, SND_FILENAME|SND_ASYNC) elif sys.platform.find('linux')>-1: from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(file,'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) dsp = ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
def run(self): if self.what != "None": bgm = waveOpen("bgm_mouthmoney.wav", "rb") self.keeprunning = True reses = [] while (self.keeprunning): if len(reses) >= 128: #TODO #Abspielen self.soundout.stdin.write(b"".join(reses)) reses = [] if self.scheduled and self.what != "bgm": scheduled = self.scheduled read0 = bgm.readframes(4) if not read0: bgm.rewind() continue read1 = scheduled.readframes(4) if not read1: self.scheduled = None reses.append(read0) continue try: reses.append(add(read0, read1, 4)) except: pass #really? else: read = bgm.readframes(256) if not read: bgm.rewind() continue reses.append(read)
def _playsoundNix(sound, block=True): ''' Utilizes ossaudiodev. Untested. Probably works with all version of Linux with Python 2.3 or newer. Inspired by, and more or less copied from, Bill Dandreta's post on this mailing list (since deleted, so I link to a web archive instead): https://web.archive.org/web/20080218155209/http://mail.python.org/pipermail/python-list/2004-October/288905.html ''' import ossaudiodev from sys import byteorder from wave import open as waveOpen, AFMT_S16_LE, AFMT_S16_BE with waveOpen(sound, 'rb') as sound: channelCount, sampleWidth, framerate, frameCount, compressionType, compressionName = sound.getparams( ) try: from ossaudiodev import AFMT_S16_NE except ImportError: if 'little' in byteorder.lower(): AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE data = sound.readframes(frameCount) speaker = ossaudiodev.open('/dev/dsp', 'w') speaker.setparameters(AFMT_S16_NE, channelCount, framerate) speaker.write(data) speaker.close()
def run(self): if self.what != "None": bgm = waveOpen("bgm_mouthmoney.wav", "rb") self.keeprunning = True reses = [] while(self.keeprunning): if len(reses) >= 128: #TODO #Abspielen self.soundout.stdin.write(b"".join(reses)) reses = [] if self.scheduled and self.what != "bgm": scheduled = self.scheduled read0 = bgm.readframes(4) if not read0: bgm.rewind() continue read1 = scheduled.readframes(4) if not read1: self.scheduled = None reses.append(read0) continue try: reses.append(add(read0, read1, 4)) except: pass #really? else: read = bgm.readframes(256) if not read: bgm.rewind() continue reses.append(read)
def _play(soundfile): if platform.startswith('win'): from winsound import PlaySound, SND_FILENAME, SND_ASYNC PlaySound(soundfile, SND_FILENAME|SND_ASYNC) elif 'linux' in platform: from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(soundfile,'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp = None try: dsp = ossOpen('/dev/dsp','w') dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) except IOError: print >> stderr, _("Audio device is busy.") finally: if dsp: dsp.close()
def graj(self): if self.dzwiek and self.plik != "": if platform.system() == "Windows": from winsound import PlaySound, SND_FILENAME, SND_ASYNC PlaySound(self.plik, SND_FILENAME | SND_ASYNC) elif platform.system() == "Linux": from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(self.plik, "rb") (nc, sw, fr, nf, comptype, compname) = s.getparams() try: dsp = ossOpen("/dev/dsp", "w") try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) dsp.write(data) s.close() dsp.close() except IOError: print "Błąd pisania do użądzenia /dev/dsp !" print "Sprawdź czy masz możliwość zapisywania lub czy w Twoim systemie \ jest załadowany moduł snd-pcm-oss, jeżeli nie jest załaduj go jako root poleceniem" print "\n\tmodprobe snd-pcm-oss"
def saveSample(self) -> bool: '''Saves the curent sample to the audio file. If the file does not exists, it is created. If the sample length is not equal to the self.sampleLength value, it means, we've cut the silence at the end of the sample, so it's the end of the file and it should be closed. The function returns True on success or if the recording is off, False otherwise.''' if not self.recording: return True try: if self.sampleLength: finalSample = True else: # If sampleLength wasn't set manualy, all the sample is saved. # It means the recording isn't over yet. self.sampleLength = len(self.sample) finalSample = False self.audioFileLength += self.sampleLength recordLength = (float(self.audioFileLength) / self.outputSecondSize) if recordLength > self.minRecordingLength: # The save-to-file process starts only when the sample is long enough if not self.audioFile: # Creating the file if necessary self.audioFile = waveOpen(self.fileName, 'wb') assert self.audioFile self.audioFile.setnchannels(self.numOutputChannels) self.audioFile.setsampwidth(self.audioBytes) self.audioFile.setframerate(self.sampleRate) self.audioFile.writeframes( self.sample[:self.sampleLength] ) # Removing extra silence at the end, if needed self.sample = b'' self.sampleLength = 0 if finalSample or not self.inLoop: self.recording = False self.audioFile.close() self.audioFile = None self.logger.info( f"Recording finished, max volume {self.localMaxVolume:.2f}%, {recordLength:.1f} seconds" ) return True if finalSample or not self.inLoop: self.recording = False self.logger.info( f"Recording discarded as it's too short ({recordLength:.1f} seconds)" ) else: self.audioFileLength -= self.sampleLength # If the sample is short we do not operate with it, so param changes should be undone return True except Exception as e: self.logger.warning( f"File output error: {(type(e).__name__)}: {e}") return False
def three(): s = waveOpen(os.path.join(os.path.dirname(__file__), '1.wav'), 'rb') nc, sw, fr, nf, comptype, compname = s.getparams() dsp = ossOpen('/dev/dsp','w') dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
def _play(self, filename): if platform.startswith('win'): PlaySound(filename, SND_FILENAME|SND_ASYNC) else: s = waveOpen(filename,'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams() self.dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() self.dsp.write(data)
def play_sound(filename): try: s = waveOpen(os.path.abspath(os.path.dirname(sys.argv[0])) + '/lukas-sounds/' + filename, 'rb') except Exception: print "Sound file not found" return (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp.setparameters(AFMT_S16_NE, nc, fr) dsp.write(s.readframes(nf)) s.close()
def openWave(fname): if fname!=None: dat["gfname"]=fname dat["s"] = waveOpen(dat["gfname"],'rb') nc,sw,fr,nf,comptype, compname = dat["s"].getparams() dat["nf"]=nf dat["nc"]=nc dat["sw"]=sw dat["fr"]=fr dat["comptype"]=comptype dat["compname"]=compname
def make_sound_alert(self): if self.panel.sound_mode == dc.SOUND_ON: file_name = '/home/feike/BoomstraDam/images/whistl~1.wav' s = waveOpen(file_name, 'rb') (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp = ossOpen('/dev/dsp', 'w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close() elif self.panel.sound_mode == dc.SOUND_OFF: pass elif self.panel.sound_mode == dc.SOUND_TWO: file_name = '/home/feike/BoomstraDam/images/whistl~1.wav' s = waveOpen(file_name, 'rb') (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp = ossOpen('/dev/dsp', 'w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close() return
def play_wav(file_name): from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(file_name, "rb") (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp = ossOpen("/dev/dsp", "w") from ossaudiodev import AFMT_S16_NE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
def _get_wav(self, file_name): """ Returns a WaveData instance from the self._wav_file property, keeping it in a cache dictionary for subsequent calls. """ if file_name not in self._cache: try: wav_file = waveOpen(file_name, 'rb') nc, sw, fr, nf, comptype, compname = wav_file.getparams() self._cache[file_name] = WavData(nc, fr, nf, wav_file.readframes(nf)) wav_file.close() except Exception as exc: self._cache[file_name] = None print(exc) return self._cache[file_name]
def wav_to_dsp(wav_path): try: s = waveOpen(wav_path, 'rb') dsp = ossOpen('/dev/dsp','w') nc, sw, fr, nf, comptype, compname = s.getparams() dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) dsp.write(data) finally: for obj in s, dsp: try: getattr(obj, 'close')() except Exception: pass
def playWave(fileName): """ Play wave file cross platform """ if PLATFORM == 'nt': from winsound import PlaySound, SND_FILENAME, SND_ASYNC PlaySound(fileName, SND_FILENAME|SND_ASYNC) elif PLATFORM == 'posix' and SOUND_ENV == 'standard': from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(fileName, 'rb') (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp = ossOpen('/dev/dsp2', 'w') from ossaudiodev import AFMT_S16_LE dsp.setparameters(AFMT_S16_LE, nc, fr) data = s.readframes(nf) s.close() dsp.writeall(data) dsp.close()
def Play(filename): """Plays the sound in the given filename, asynchronously.""" if platform.system().startswith('Win'): PlaySound(filename, SND_FILENAME|SND_ASYNC) elif platform.system().startswith('Linux'): try: s = waveOpen(filename,'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) dsp = ossOpen('/dev/dsp','w') dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close() except: pass
def ossplay(filename): # play audio thru oss from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(filename, 'rb') (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp = ossOpen('/dev/dsp', 'w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
def ossplay(filename): # play audio thru oss from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(filename,'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) dsp = ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
def _playsoundNix(sound, block=True): import ossaudiodev from sys import byteorder from wave import open as waveOpen with waveOpen(sound, 'rb') as sound: channelCount, sampleWidth, framerate, frameCount, compressionType, compressionName = sound.getparams( ) try: from ossaudiodev import AFMT_S16_NE except ImportError: if 'little' in byteorder.lower(): AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE data = sound.readframes(frameCount) speaker = ossaudiodev.open('/dev/dsp', 'w') speaker.setparameters(AFMT_S16_NE, channelCount, framerate) speaker.write(data) speaker.close()
def alarm_gempa(self): s = waveOpen('/usr/share/sounds/pyews/gempa.wav', 'rb') (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp = ossOpen('/dev/dsp', 'w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() for i in range(1, 5): dsp.write(data) dsp.close()
def alarm_gempa(self): s = waveOpen('/usr/share/sounds/pyews/gempa.wav','rb') (nc,sw,fr,nf,comptype, compname) = s.getparams() dsp = ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() for i in range(1,5): dsp.write(data) dsp.close()
def run_sound(sound_id): sound_file = SystemPath + Sounds[sound_id] # check operating system because sounds have to played in different ways for different operating systems. if _platform == "linux" or _platform == "linux2": # linux # this is going to be a bit more complex from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(sound_file,'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) dsp = ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close() return True elif _platform == "darwin": # OS X 10.5 import subprocess return_code = subprocess.call(["afplay", sound_file]) return True elif _platform == "win32": # Windows... import winsound winsound.PlaySound('%s' % sound_file, winsound.SND_FILENAME) return True return False
def run(self): try: s = waveOpen(self.aFile,'rb') except: return (nc,sw,fr,nf,comptype, compname) = s.getparams( ) try: dsp = ossOpen('/dev/dsp','w') except: return try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
def run(lol): plat = platform.system().lower() if plat.startswith('win'): from winsound import PlaySound, SND_FILENAME, SND_ASYNC PlaySound(lol.fn, SND_FILENAME | SND_ASYNC) elif plat.find('linux') > -1: from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(lol.fn, 'rb') (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp = ossOpen('/dev/dsp', 'w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
def run(lol): plat = platform.system().lower() if plat.startswith('win'): from winsound import PlaySound, SND_FILENAME, SND_ASYNC PlaySound(lol.fn, SND_FILENAME|SND_ASYNC) elif plat.find('linux')>-1: from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(lol.fn, 'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams() dsp = ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
# testing wav sound in python (not working) # IOError: [Errno 2] No such file or directory: '/dev/dsp' from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen('tada.wav', 'rb') (nc, sw, fr, nf, comptype, compname) = s.getparams() dsp = ossOpen('w') #ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: from sys import byteorder if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
from sys import argv from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(argv[1],'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) dsp = ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen('MAS.wav','rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) dsp = ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: from sys import byteorder if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()
def play(self, filename): self.scheduled = waveOpen(filename, "rb")
file='test.wav' myfile = open(file, "wb") s = bv.GetPointer() for i in range(0, l): myfile.write(s[i]) myfile.close() # http://mail.python.org/pipermail/python-list/2004-October/288905.html if sys.platform.startswith('win'): from winsound import PlaySound, SND_FILENAME, SND_ASYNC PlaySound(file, SND_FILENAME|SND_ASYNC) elif sys.platform.find('linux')>-1: from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen(file,'rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) dsp = ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close()