def get_length(self): """ Get length of sound sample. """ stream = AudioSystem.getAudioInputStream(self._sound_object) length = stream.getFrameLength() / stream.getFormat().getFrameRate() stream.close() return length
def length_of_audio_file_in_secs(file_path): audioInputStream = AudioSystem.getAudioInputStream(java.io.File(file_path)) format_ = audioInputStream.getFormat() frames = audioInputStream.getFrameLength() return float(frames) / format_.getFrameRate()
def _set_sound(self, sound): self._sound = sound self._stream = AudioSystem.getAudioInputStream(sound._sound_object)
from java.io import File from javax.sound.sampled import AudioInputStream from javax.sound.sampled import AudioSystem from javax.sound.sampled import Clip from java.lang import Thread, Runnable file = File( "C:\\Users\\Sony\\Desktop\\jython-prac-prog\\network\\sample_audio.wav") stream = AudioSystem.getAudioInputStream(file) clip = AudioSystem.getClip() print(type(clip)) class f(Runnable): def __init__(self, x): self.x = x def run(self): self.x.open(stream) self.x.start() g = f(clip) k = Thread(g) k.start() Thread.sleep(500) print("End") #Thread.sleep(35000) stream.close()
def _get_stream(self): if isinstance(self._sound_object, File): return AudioSystem.getAudioInputStream(self._sound_object) else: return ByteArrayInputStream(self._sound_object)
def _get_sound_object(self, sound_file): stream = AudioSystem.getAudioInputStream(sound_file) sound_object = jarray.zeros(stream.available(), 'b') stream.read(sound_object) stream.close() return sound_object