Recherche avancée

Médias (0)

Mot : - Tags -/metadatas

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (85)

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

  • MediaSPIP Init et Diogène : types de publications de MediaSPIP

    11 novembre 2010, par

    À l’installation d’un site MediaSPIP, le plugin MediaSPIP Init réalise certaines opérations dont la principale consiste à créer quatre rubriques principales dans le site et de créer cinq templates de formulaire pour Diogène.
    Ces quatre rubriques principales (aussi appelées secteurs) sont : Medias ; Sites ; Editos ; Actualités ;
    Pour chacune de ces rubriques est créé un template de formulaire spécifique éponyme. Pour la rubrique "Medias" un second template "catégorie" est créé permettant d’ajouter (...)

  • Le plugin : Podcasts.

    14 juillet 2010, par

    Le problème du podcasting est à nouveau un problème révélateur de la normalisation des transports de données sur Internet.
    Deux formats intéressants existent : Celui développé par Apple, très axé sur l’utilisation d’iTunes dont la SPEC est ici ; Le format "Media RSS Module" qui est plus "libre" notamment soutenu par Yahoo et le logiciel Miro ;
    Types de fichiers supportés dans les flux
    Le format d’Apple n’autorise que les formats suivants dans ses flux : .mp3 audio/mpeg .m4a audio/x-m4a .mp4 (...)

Sur d’autres sites (8040)

  • Run python ffmpeg audio convertion code file from subprocess.call() within a flask server

    11 novembre 2019, par Kasun

    I have build a small flask server to handle the request. I have 3 parameters in the api function that i want to get. those are type, user_id, audio_file, One is a file. Since it’s used for the audio file conversion. I have to get a file.. I have tested with this in Postman audio file get saved but the subprocess.call(command) in the api function doesn’t work..

    this is the flask server code

    @app.route('/voice', methods=['GET','POST'])
    def process_audio():
    try:
       if request.method == 'POST':
           input_type = request.form['type']
           user_id = request.form['user_id']
           static_file = request.files['audio_file']
           audio_name = secure_filename(static_file.filename)
           path = 't/'
           status = static_file.save(path + audio_name)
           full_file = path + audio_name
           if input_type == 1:
               cmd = "python t/convert_english.py --audio " + full_file
               res = subprocess.call([cmd],shell=True)
               f = open('t/ress.txt', 'w')
               f.write(str(res))
               f.close()
               return "true"
           else:
               cmd = "python t/convert_sinhala.py --audio " + full_file
               os.system(cmd)
               return "true"
       else:
           return "false"

    except Exception as e:
       print(e)
       logger.error(e)
       return e

    The audio file get saved in the directory as expected..

    this is the convert_english.py

    import subprocess
    import argparse
    import os
    import logging
    import speech_recognition as sr
    from tqdm import tqdm
    from multiprocessing.dummy import Pool

    #subprocess.call('pip install pydub',shell=True)

    from os import path
    from pydub import AudioSegment

    logging.basicConfig(filename='/var/www/img-p/t/ee.log', level=logging.DEBUG,
                       format='%(asctime)s %(levelname)s %(name)s %(message)s')
    logger=logging.getLogger(__name__)

    ap = argparse.ArgumentParser()
    ap.add_argument("-a", "--audio", required=True,
       help="path to input audio file")
    args = vars(ap.parse_args())

    src = args["audio"]
    dst = "audio.wav"

    sound = AudioSegment.from_mp3(src)
    sound.export(dst, format="wav")

    #subprocess.call('pip install ffmpeg-python',shell=True)

    subprocess.call('mkdir parts',shell=True)

    subprocess.call('ffmpeg -i audio.wav -f segment -segment_time 30 -c copy parts/out%09d.wav',shell=True)

    #subprocess.call('pip install SpeechRecognition',shell=True)


    pool = Pool(8) # Number of concurrent threads

    with open("api-key.json") as f:
       GOOGLE_CLOUD_SPEECH_CREDENTIALS = f.read()

    r = sr.Recognizer()
    files = sorted(os.listdir('parts/'))

    def transcribe(data):
       idx, file = data
       name = "parts/" + file
       print(name + " started")
       # Load audio file
       with sr.AudioFile(name) as source:
           audio = r.record(source)
       # Transcribe audio file
       text = r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS)
       print(name + " done")
       return {
           "idx": idx,
           "text": text
       }

    all_text = pool.map(transcribe, enumerate(files))
    pool.close()
    pool.join()

    transcript = ""
    for t in sorted(all_text, key=lambda x: x['idx']):
       total_seconds = t['idx'] * 30
       # Cool shortcut from:
       # https://stackoverflow.com/questions/775049/python-time-seconds-to-hms
       # to get hours, minutes and seconds
       m, s = divmod(total_seconds, 60)
       h, m = divmod(m, 60)

       # Format time as h:m:s - 30 seconds of text
       transcript = transcript + "{:0>2d}:{:0>2d}:{:0>2d} {}\n".format(h, m, s, t['text'])

    print(transcript)

    with open("transcript.txt", "w") as f:
       f.write(transcript)

    f = open("transcript.txt")
    lines = f.readlines()
    f.close()
    f = open("transcript.txt", "w", encoding="utf-8")
    for line in lines:
       f.write(line[8:])
    f.close()

    The thing is above code works when i manually run the command -> python t/convert_english.py —audio t/tttttttttt.mp3 like this in the terminal..

    But when i try to run from the flask server itself it doesn’t works.. And I’m not getting an error either.

  • pydub.exceptions.CouldntDecodeError : Decoding failed. ffmpeg returned error code : 1

    9 avril, par azail765

    This script will work on a 30 second wav file but not a 10 minutes phone call also in wav format. Any help would be appreciated

    


    I've downloaded ffmpeg.

    


    # Import necessary libraries 
from pydub import AudioSegment 
import speech_recognition as sr 
import os
import pydub


chunk_count = 0
directory = os.fsencode(r'C:\Users\zach.blair\Downloads\speechRecognition\New folder')
# Text file to write the recognized audio 
fh = open("recognized.txt", "w+")
for file in os.listdir(directory):
     filename = os.fsdecode(file)
     if filename.endswith(".wav"):
        chunk_count += 1
             # Input audio file to be sliced 
        audio = AudioSegment.from_file(filename,format="wav") 
          
        ''' 
        Step #1 - Slicing the audio file into smaller chunks. 
        '''
        # Length of the audiofile in milliseconds 
        n = len(audio) 
          
        # Variable to count the number of sliced chunks 
        counter = 1
          
         
          
        # Interval length at which to slice the audio file. 
        interval = 20 * 1000
          
        # Length of audio to overlap.  
        overlap = 1 * 1000
          
        # Initialize start and end seconds to 0 
        start = 0
        end = 0
          
        # Flag to keep track of end of file. 
        # When audio reaches its end, flag is set to 1 and we break 
        flag = 0
          
        # Iterate from 0 to end of the file, 
        # with increment = interval 
        for i in range(0, 2 * n, interval): 
              
            # During first iteration, 
            # start is 0, end is the interval 
            if i == 0: 
                start = 0
                end = interval 
          
            # All other iterations, 
            # start is the previous end - overlap 
            # end becomes end + interval 
            else: 
                start = end - overlap 
                end = start + interval  
          
            # When end becomes greater than the file length, 
            # end is set to the file length 
            # flag is set to 1 to indicate break. 
            if end >= n: 
                end = n 
                flag = 1
          
            # Storing audio file from the defined start to end 
            chunk = audio[start:end] 
          
            # Filename / Path to store the sliced audio 
            filename = str(chunk_count)+'chunk'+str(counter)+'.wav'
          
            # Store the sliced audio file to the defined path 
            chunk.export(filename, format ="wav") 
            # Print information about the current chunk 
            print(str(chunk_count)+str(counter)+". Start = "
                                +str(start)+" end = "+str(end)) 
          
            # Increment counter for the next chunk 
            counter = counter + 1
              
          
            AUDIO_FILE = filename 
            
            # Initialize the recognizer 
            r = sr.Recognizer() 
          
            # Traverse the audio file and listen to the audio 
            with sr.AudioFile(AUDIO_FILE) as source: 
                audio_listened = r.listen(source) 
          
            # Try to recognize the listened audio 
            # And catch expections. 
            try:     
                rec = r.recognize_google(audio_listened) 
                  
                # If recognized, write into the file. 
                fh.write(rec+" ") 
              
            # If google could not understand the audio 
            except sr.UnknownValueError: 
                    print("Empty Value") 
          
            # If the results cannot be requested from Google. 
            # Probably an internet connection error. 
            except sr.RequestError as e: 
                print("Could not request results.") 
          
            # Check for flag. 
            # If flag is 1, end of the whole audio reached. 
            # Close the file and break.                  
fh.close()    


    


    I get this error on audio = AudioSegment.from_file(filename,format="wav") :

    


    Traceback (most recent call last):&#xA;  File "C:\Users\zach.blair\Downloads\speechRecognition\New folder\speechRecognition3.py", line 17, in <module>&#xA;    audio = AudioSegment.from_file(filename,format="wav")&#xA;  File "C:\Users\zach.blair\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\audio_segment.py", line 704, in from_file&#xA;    p.returncode, p_err))&#xA;pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 1&#xA;</module>

    &#xA;

    Output from ffmpeg/avlib :

    &#xA;

      ffmpeg version N-95027-g8c90bb8ebb Copyright (c) 2000-2019 the FFmpeg developers&#xA;  built with gcc 9.2.1 (GCC) 20190918&#xA;  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf&#xA;  libavutil      56. 35.100 / 56. 35.100&#xA;  libavcodec     58. 58.101 / 58. 58.101&#xA;  libavformat    58. 33.100 / 58. 33.100&#xA;  libavdevice    58.  9.100 / 58.  9.100&#xA;  libavfilter     7. 58.102 /  7. 58.102&#xA;  libswscale      5.  6.100 /  5.  6.100&#xA;  libswresample   3.  6.100 /  3.  6.100&#xA;  libpostproc    55.  6.100 / 55.  6.100&#xA;Guessed Channel Layout for Input Stream #0.0 : mono&#xA;Input #0, wav, from &#x27;2a.wav.wav&#x27;:&#xA;  Duration: 00:09:52.95, bitrate: 64 kb/s&#xA;    Stream #0:0: Audio: pcm_mulaw ([7][0][0][0] / 0x0007), 8000 Hz, mono, s16, 64 kb/s&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (pcm_mulaw (native) -> pcm_s8 (native))&#xA;Press [q] to stop, [?] for help&#xA;[wav @ 0000024307974400] pcm_s8 codec not supported in WAVE format&#xA;Could not write header for output file #0 (incorrect codec parameters ?): Function not implemented&#xA;Error initializing output stream 0:0 -- &#xA;Conversion failed!&#xA;

    &#xA;

  • Is there way to compile ffmpeg in VS 2019 without (1) installing MSYS, (2) using assembler sources ? [duplicate]

    21 octobre 2023, par Tobic

    I want to compile ffmpeg in VS 2019 without installing additional components such as MSYS and assembler sources.&#xA;If I understand correctly, I have to install MSYS to do that and I would like not install it.

    &#xA;

    Can I do it without MSYS - and if it is real, in what way ?
    &#xA;I have downloaded ffmpeg sources and the first step to install it - execute a file .\configure (bash script ?) that comes with ffmpeg.

    &#xA;