def upload(): print "hehe" file = request.files['file'] print file format = "%Y-%m-%dT%H:%M:%S" now = datetime.utcnow().strftime(format) print now filename = now + '_' + file.filename print filename fullpath = os.path.join('upload_folder', filename) # .m4a file.save(fullpath) at = audiotranscode.AudioTranscode() at.transcode(fullpath, fullpath + ".mp3") file_uploaded = True totalPoints, totalPasses, totalShots = Check(fullpath + ".mp3") return jsonify( pointA=totalPoints, pointB=totalPoints, passA=totalPasses, passB=totalPasses, shotA=totalShots, shotB=totalShots, )
def __init__(self): CherryModel.NATIVE_BROWSER_FORMATS = ['opus', 'ogg', 'mp3'] CherryModel.supportedFormats = CherryModel.NATIVE_BROWSER_FORMATS[:] if cherry.config['media.transcode']: self.transcoder = audiotranscode.AudioTranscode() formats = CherryModel.supportedFormats formats += self.transcoder.available_decoder_formats() CherryModel.supportedFormats = list(set(formats))
def get_sample(path_ogg): """ :param path_ogg: path to .ogg file :return: samples of audio file and its sample rate """ path_wav = path_ogg[:-3] + 'wav' # Convert .ogg to .wav format if OS == 'mac': at = audiotranscode.AudioTranscode() at.transcode(path_ogg, path_wav) elif OS == 'linux': at = audiotranscode.AudioTranscode() at.transcode(path_ogg, path_wav) # ogg_to_wav(path_ogg, path_wav) (samples, sample_rate) = sf.read(path_wav) return samples, sample_rate
def command_test2(self): print(args.path) files = self.getAudioFiles() at = audiotranscode.AudioTranscode(debug=True) print(at.available_encoder_formats()) print(at.available_decoder_formats()) for file in files: at.transcode(file, 'D:/project/test.ogg', bitrate=128) return # print ("files=\n" + '\r\n'.join(files))\ #ffmpeg -i E:\quickv3\sanguosha\res\audio\skill\SKILL_32_1_2.mp3 -f wav - |oggenc2 -q 0 -Q - -o D:/project/SKILL_32_1_2.ogg pass
def trans(self, newformat, *path, **params): ''' Transcodes the track given as ``path`` into ``newformat``. Streams the response of the corresponding ``audiotranscode.AudioTranscode().transcodeStream()`` call. params: bitrate: int for kbps. None or < 1 for default ''' if not self.isAuthorized(): raise cherrypy.HTTPRedirect(self.getBaseUrl(), 302) cherrypy.session.release_lock() if cherry.config['media.transcode'] and path: # bitrate bitrate = params.pop('bitrate', None) or None # catch empty strings if bitrate: try: bitrate = max(0, int(bitrate)) or None # None if < 1 except (TypeError, ValueError): raise cherrypy.HTTPError( 400, "Bad query: " "bitrate ({0!r}) must be an integer".format( str(bitrate))) # path path = os.path.sep.join(path) if sys.version_info < (3, 0): # workaround for #327 (cherrypy issue) path = path.decode('utf-8') # make it work with non-ascii else: path = codecs.decode(codecs.encode(path, 'latin1'), 'utf-8') fullpath = os.path.join(cherry.config['media.basedir'], path) starttime = int(params.pop('starttime', 0)) transcoder = audiotranscode.AudioTranscode() mimetype = transcoder.mimeType(newformat) cherrypy.response.headers["Content-Type"] = mimetype try: return transcoder.transcodeStream(fullpath, newformat, bitrate=bitrate, starttime=starttime) except audiotranscode.TranscodeError as e: raise cherrypy.HTTPError(404, e.value)
def trans(self, *args): if not self.isAuthorized(): raise cherrypy.HTTPRedirect(self.getBaseUrl(), 302) cherrypy.session.release_lock() if cherry.config['media.transcode'] and len(args): newformat = args[-1][4:] # get.format path = os.path.sep.join(args[:-1]) """ugly workaround for #273, should be handled somewhere in cherrypy, but don't know where... """ if sys.version_info < (3, 0): path = path else: path = codecs.decode(codecs.encode(path, 'latin1'), 'utf-8') fullpath = os.path.join(cherry.config['media.basedir'], path) transcoder = audiotranscode.AudioTranscode() mimetype = transcoder.mimeType(newformat) cherrypy.response.headers["Content-Type"] = mimetype return transcoder.transcodeStream(fullpath, newformat)
import audiotranscode import requests at = audiotranscode.AudioTranscode() def get_audio_file(audio_url): r = requests.get(audio_url) with open('audio.mp3', 'wb') as f: f.write(r.content) def aac_to_mp3(audio_file='audio.wav', output_file='audio.mp3'): conversion = at.transcode(audio_file, output_file) return conversion url = 'https://cdn.fbsbx.com/v/t59.3654-21/17695304_10211588381840935_4291541419631312896_n.aac/audioclip-1491740374478-3932.aac?oh=ba0c59a8c4f0b45bdb7c0a1ba43fdddd&oe=58EC35CC' aac_to_mp3()
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> # import os import tempfile from nose.tools import * import audiotranscode as transcode CAPTURE_OUTPUT = True transcoder = transcode.AudioTranscode(debug=True) inputdir = os.path.dirname(__file__) outputpath = tempfile.mkdtemp(prefix='test.cherrymusic.audiotranscode.') testfiles = { 'mp3': os.path.join(inputdir, 'test.mp3'), 'ogg': os.path.join(inputdir, 'test.ogg'), 'flac': os.path.join(inputdir, 'test.flac'), 'wav': os.path.join(inputdir, 'test.wav'), } def setup_module(): if CAPTURE_OUTPUT: print('writing transcoder output to %r' % (outputpath, ))
def __init__(self): self.audio_transcode = audiotranscode.AudioTranscode() self.tmp_file = "tmp."