当前位置: 首页>>代码示例>>Python>>正文


Python AudioSegment.from_mp3方法代码示例

本文整理汇总了Python中pydub.AudioSegment.from_mp3方法的典型用法代码示例。如果您正苦于以下问题:Python AudioSegment.from_mp3方法的具体用法?Python AudioSegment.from_mp3怎么用?Python AudioSegment.from_mp3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydub.AudioSegment的用法示例。


在下文中一共展示了AudioSegment.from_mp3方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
    def setUp(self):
        global test1, test2, test3, testparty, testdcoffset
        if not test1:
            a = os.path.join(data_dir, 'test1.mp3')
            test1 = AudioSegment.from_mp3(os.path.join(data_dir, 'test1.mp3'))
            test2 = AudioSegment.from_mp3(os.path.join(data_dir, 'test2.mp3'))
            test3 = AudioSegment.from_mp3(os.path.join(data_dir, 'test3.mp3'))
            testdcoffset = AudioSegment.from_mp3(
                os.path.join(data_dir, 'test-dc_offset.wav'))
            testparty = AudioSegment.from_mp3(
                os.path.join(data_dir, 'party.mp3'))

        self.seg1 = test1
        self.seg2 = test2
        self.seg3 = test3
        self.mp3_seg_party = testparty
        self.seg_dc_offset = testdcoffset

        self.ogg_file_path = os.path.join(data_dir, 'bach.ogg')
        self.mp4_file_path = os.path.join(data_dir, 'creative_common.mp4')
        self.mp3_file_path = os.path.join(data_dir, 'party.mp3')
        self.webm_file_path = os.path.join(data_dir, 'test5.webm')

        self.jpg_cover_path = os.path.join(data_dir, 'cover.jpg')
        self.png_cover_path = os.path.join(data_dir, 'cover.png')
开发者ID:jiaaro,项目名称:pydub,代码行数:27,代码来源:test.py

示例2: MangleLibrary

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
def MangleLibrary(src, dst, audio, splice=None):
	if os.path.splitext(audio)[1] != ".mp3":
		raise "Prank audio is not an mp3"
	prank = AudioSegment.from_mp3(audio)
	# Walk src
	for root, dirs, files in os.walk(src):
		# Loop through files in this dir
		for fn in files:
			# If file is an mp3
			if os.path.splitext(fn)[1] == ".mp3":
				# Import song
				fullsong = AudioSegment.from_mp3(root+"/"+fn)
				# Pick random location between 10s and end of song
				start = random.randint(15,60)
				print("Spliced {} after {} seconds".format(root+"/"+fn,start))
				# Splice in prank song
				if splice != None:
					r = random.randint(0,len(splice)-1)
					final = fullsong[:start*1000] + prank[splice[r][0]:splice[r][1]] + fullsong[start*1000:]
					# final = fullsong[:start*1000] + prank + fullsong[start*1000:]
				else:
					final = fullsong[:start*1000] + prank
				# Recreate directory structrue in dst
				if not os.path.exists(dst+"/"+root):
					os.makedirs(dst+"/"+root)
				# Export song with tags
				final.export(dst+"/"+root+"/"+fn, format="mp3", tags=mediainfo(root+"/"+fn).get('TAG', {}))
开发者ID:buchanan,项目名称:LM,代码行数:29,代码来源:__init__.py

示例3: setUp

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
 def setUp(self):
     global test1, test2, test3
     if not test1:
         test1 = AudioSegment.from_mp3(os.path.join(data_dir, 'test1.mp3'))
         test2 = AudioSegment.from_mp3(os.path.join(data_dir, 'test2.mp3'))
         test3 = AudioSegment.from_mp3(os.path.join(data_dir, 'test3.mp3'))
     self.seg1, self.seg2, self.seg3 = test1, test2, test3 
开发者ID:handloomweaver,项目名称:pydub,代码行数:9,代码来源:test.py

示例4: start

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
	def start(self):
		# Server runs until killed
		while True:
			# If we have a request, play it
			if len(self.request_list) != 0:
				self.current_song = AudioSegment.from_mp3("../songs/" + self.request_list.popleft())
			# Otherwise, play a random song
			else:
				self.current_song = AudioSegment.from_mp3("../songs/" + random.choice(self.songlist))
			self.new_song()
			# Stream the entire song
			for chunk in self.current_song:
				# Simply skip the time for the client
				if not self.has_client:
					sleep(0.001)
				else:
					# Stream chunk to first client
					client, address = self.clients[0]
					try:
						chunk = chunk.raw_data
						chunk = chunk[:self.chunk_size].ljust(self.chunk_size)
						chunk_length = str(len(chunk))
						client.sendto(bytes("SC" + chunk_length + (4-len(chunk_length))*" ", "UTF-8"), address)
						client.sendto(chunk, address)
					# Disconnects will be handled, just maybe not on time to avoid
					#	this error a few times. We just ignore the error
					except BrokenPipeError:
						pass
开发者ID:kahns729,项目名称:comp112-final-project,代码行数:30,代码来源:stream.py

示例5: _audio_from_to

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
def _audio_from_to(input_file, ext, start, end, output_dir):
    output_path = os.path.join(output_dir, ''.join([
        'audio_', str(start), '-', str(end), ext]))
    if pathutil.isfile(output_path):
        return output_path
    AudioSegment.from_mp3(input_file)[
        int(start * 1000): int(end * 1000)].export(output_path, format='mp3')
    return output_path
开发者ID:neuront,项目名称:madmagia,代码行数:10,代码来源:audio_slice.py

示例6: test2

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
def test2():
    src= AudioSegment.from_mp3(r'Output_audio\part_from_join.mp3')
    l = len(src)
    seek= AudioSegment.from_mp3(r'Input_audio\1bdcf42e-1bdb-4058-b9e5-6ee670ec509b.mp3')
    r = findSound(src, 0, l, seek)

    print(r)    
    return True    
开发者ID:avp1983,项目名称:transcription,代码行数:10,代码来源:plot.py

示例7: logData

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
def logData():  
    src= AudioSegment.from_mp3(r'Output_audio\part_from_join.mp3') 
    log(r'Output_audio\part_from_join.mp3') 
    logRms(src)
    log('---------')
    src= AudioSegment.from_mp3(r'Input_audio\1bdcf42e-1bdb-4058-b9e5-6ee670ec509b.mp3')
    log(r'Input_audio\1bdcf42e-1bdb-4058-b9e5-6ee670ec509b.mp3')
    logRms(src)
    log('---------')
开发者ID:avp1983,项目名称:transcription,代码行数:11,代码来源:plot.py

示例8: say

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
 def say(self, sentence):
     print "say method"
     fullSentence = AudioSegment.from_mp3(sentence[0])
     for i in range(1, len(sentence)):
         print "sentence[i] ", sentence[i]
         wordToPlay = AudioSegment.from_mp3(sentence[i])
         fullSentence += wordToPlay
     print "Ready to play"
     play(fullSentence)
开发者ID:RaphaD,项目名称:VIAAC,代码行数:11,代码来源:VIAACVoice.py

示例9: test1

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
def test1():
    src= AudioSegment.from_mp3(r'Input_audio\1bdcf42e-1bdb-4058-b9e5-6ee670ec509b.mp3')
    l = len(src)
    seek= AudioSegment.from_mp3(r'Input_audio\1bdcf42e-1bdb-4058-b9e5-6ee670ec509b.mp3')
    r = findSound(src, 0, l, seek)
    if r!=[0, l]:
        raise Exception('test1 not passed')
    print(r)    
    return True    
开发者ID:avp1983,项目名称:transcription,代码行数:11,代码来源:plot.py

示例10: test_audio_segment_from_mp3

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
 def test_audio_segment_from_mp3(self):
     seg1 = AudioSegment.from_mp3(os.path.join(data_dir, 'test1.mp3'))
     
     mp3_file = open(os.path.join(data_dir, 'test1.mp3'), 'rb')
     seg2 = AudioSegment.from_mp3(mp3_file)
     
     self.assertEqual(len(seg1), len(seg2))
     self.assertTrue(seg1._data == seg2._data)
     self.assertTrue(len(seg1) > 0)
开发者ID:handloomweaver,项目名称:pydub,代码行数:11,代码来源:test.py

示例11: test_for_accidental_shortening

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
    def test_for_accidental_shortening(self):
        seg = self.mp3_seg_party
        with NamedTemporaryFile('w+b', suffix='.mp3') as tmp_mp3_file:
            seg.export(tmp_mp3_file.name)

            for i in range(3):
                AudioSegment.from_mp3(tmp_mp3_file.name).export(tmp_mp3_file.name, "mp3")

            tmp_seg = AudioSegment.from_mp3(tmp_mp3_file.name)
            self.assertFalse(len(tmp_seg) < len(seg))
开发者ID:Natthaphong,项目名称:pydub,代码行数:12,代码来源:test.py

示例12: rewrite_mp3_to_wav

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
def rewrite_mp3_to_wav(source_path, target_path):
    '''
    Necessary libraries: ffmpeg, libav
    :param source_path: 
    :param target_path: 
    :return: 
    '''
    basepath, filename = os.path.split(source_path)
    os.chdir(basepath)
    AudioSegment.from_mp3(source_path).export(target_path, format='wav')
开发者ID:QianQQ,项目名称:Voice-Conversion,代码行数:12,代码来源:audio_utils.py

示例13: setUp

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
 def setUp(self):
     global test1, test2, test3
     if not test1:
         test1 = AudioSegment.from_mp3(os.path.join(data_dir, 'test1.mp3'))
         test2 = AudioSegment.from_mp3(os.path.join(data_dir, 'test2.mp3'))
         test3 = AudioSegment.from_mp3(os.path.join(data_dir, 'test3.mp3'))
     self.seg1, self.seg2, self.seg3 = test1, test2, test3
     self.ogg_file_path = os.path.join(data_dir, 'bach.ogg')
     self.mp4_file_path = os.path.join(data_dir, 'creative_common.mp4')
     self.mp3_seg_party = AudioSegment.from_mp3(os.path.join(data_dir, 'party.mp3'))
开发者ID:hihihippp,项目名称:pydub,代码行数:12,代码来源:test.py

示例14: mk_tts_tmp

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
  def mk_tts_tmp(self, texts, intro_time = 2, outro_time = 4):
    texts = listify(texts)

    segment = None
    if os.path.exists('/usr/bin/say') and self.voice in getMacVoices():
      # print 'Using OS X Say'
      text = ' '.join(texts)
      print(' ---> %s ' % text)
      tf = tempfile.mkstemp(suffix = '.aiff', dir = self.tts_workdir)
      voice_opt = ''
      voice_opt = unicodeify('-v %s' % self.voice)
      cmd = 'say %s -o %s "%s"' % (voice_opt, unicodeify(tf[1]), text)
      print(cmd)
      subprocess.check_output(['say', '-v', self.voice, '-o', unicodeify(tf[1]), text])
      tempwav = tempfile.mktemp(suffix = '.wav', dir = self.tts_workdir)
      subprocess.check_output(['ffmpeg', '-i', tf[1], '-f', 'wav', tempwav])
      # print tf[1]
      segment = AudioSegment.from_file(tempwav)
    else:
      print(texts)
      for text in texts:
        print(text)
        tf = tempfile.mkstemp(suffix = '.mp3', dir = self.tts_workdir)
        if len(text) > 99:
          print('text too longfor google tts %s' % text)
        self.get_tts_mp3(text, tf[1])
        if segment is None:
          segment = AudioSegment.from_mp3(tf[1])
        else:
          segment.append(AudioSegment.from_mp3(tf[1]))

    soundbed = AudioSegment.from_mp3('soundbed1.mp3')

    intro_time = intro_time * 1000
    outro_time = outro_time * 1000
    #print 'talking len: %s' % len(segment)
    #print 'soundbed len: %s' % len(soundbed)
    #print 'intro from 0 to %s' % soundboard_padding
    #print 'talking from %s to %s' % (intro_time, intro_time + len(segment))
    #print 'outro from %s to %s' % (
    #  intro_time + len(segment), intro_time + len(segment) + intro_time + outro_time)
    print('soundbed rms %s' % soundbed.rms)
    print('soundbed rms %s' % soundbed.sample_width)
    print('voice rms %s' % segment.rms)

    total_time_needed = intro_time + outro_time + len(segment)
    start_offset = random.randint(0, len(soundbed) - total_time_needed - 50)
    intro = soundbed[start_offset:start_offset + intro_time]
    talking = (segment + 3) * (soundbed[start_offset + intro_time:start_offset + intro_time + len(segment)]  - 4)
    outro = soundbed[start_offset + intro_time + len(segment):start_offset + intro_time + len(segment) + outro_time]
    talking_segment = intro + talking + outro
    talking_segment.fade_out(int(outro_time * 0.8))
    tf = tempfile.mkstemp(suffix = '.mp3', dir = self.tts_workdir)
    talking_segment.export(tf[1], format='mp3')
    return talking_segment
开发者ID:blackmad,项目名称:hypecast,代码行数:57,代码来源:hypecast.py

示例15: do_merge

# 需要导入模块: from pydub import AudioSegment [as 别名]
# 或者: from pydub.AudioSegment import from_mp3 [as 别名]
def do_merge(music_id, plays):
    # Download plays
    local_plays = []
    for play in plays:
        sp = play.rsplit('/', 1)
        play_name = sp[1]
        local_name = "tmp/%s--%s" % (music_id, play_name)
        urllib.urlretrieve(play, local_name)
        local_plays.append(local_name)

    # Merge plays
    sound = AudioSegment.from_mp3(local_plays[0])
    print "S0: %s" % local_plays[0]
    for i in xrange(1, len(local_plays)):
        snow = AudioSegment.from_mp3(local_plays[i])
        sound = sound.overlay(snow, position=0)

        print "S%d: %s" % (i, local_plays[i])

    exported_filename = "tmp/%s.mp3" % music_id
    exported_music = sound.export(exported_filename, "mp3")

    url = '/'.join([config.MERGIC_GAE_URL, 'conn', 'update_music'])
    data = {'SECRET_KEY': config.MERGESVR_SECRET_KEY,
            'music_id': music_id}
    files = {'file': exported_music}
    r = requests.post(url, data=data, files=files)

    # Make FileItem
    # url = '/'.join([app.config['MERGIC_GAE_URL'],
    #'conn', 'mk_fileitem_music'])
    # data = {'SECRET_KEY': app.config['MERGESVR_SECRET_KEY'],
    #         'music_id': music_id}
    # r = requests.post(url, data=data)
    # j = r.json()
    # file_id = j['file_id']
    # file_name = "%s.mp3" % file_id
    # item_name = '/'.join(['mergic_music', file_name])

    # Send merged music to CloudStorage
    # with gcs.open(item_name,
    #               'w', content_type="audio/mp3",
    #               options={'x-goog-acl': 'public-read'}) as f:
    #     f.write(exported_music.read())

    # Set Music.music_file to fileitem.id
    # url = '/'.join([app.config['MERGIC_GAE_URL'],
    #                 'conn',
    #                 'set_music_fileitem'])
    # data = {'SECRET_KEY': app.config['MERGESVR_SECRET_KEY'],
    #         'file_id': file_id,
    #         'music_id': music_id}
    # r = requests.post(url, data=data)

    print "Task finished: %s" % exported_filename
开发者ID:jangjunha,项目名称:mergic-merge,代码行数:57,代码来源:merge.py


注:本文中的pydub.AudioSegment.from_mp3方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。