Recherche avancée

Médias (2)

Mot : - Tags -/plugins

Autres articles (21)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

  • Gestion générale des documents

    13 mai 2011, par

    MédiaSPIP ne modifie jamais le document original mis en ligne.
    Pour chaque document mis en ligne il effectue deux opérations successives : la création d’une version supplémentaire qui peut être facilement consultée en ligne tout en laissant l’original téléchargeable dans le cas où le document original ne peut être lu dans un navigateur Internet ; la récupération des métadonnées du document original pour illustrer textuellement le fichier ;
    Les tableaux ci-dessous expliquent ce que peut faire MédiaSPIP (...)

  • Les vidéos

    21 avril 2011, par

    Comme les documents de type "audio", Mediaspip affiche dans la mesure du possible les vidéos grâce à la balise html5 .
    Un des inconvénients de cette balise est qu’elle n’est pas reconnue correctement par certains navigateurs (Internet Explorer pour ne pas le nommer) et que chaque navigateur ne gère en natif que certains formats de vidéos.
    Son avantage principal quant à lui est de bénéficier de la prise en charge native de vidéos dans les navigateur et donc de se passer de l’utilisation de Flash et (...)

Sur d’autres sites (5675)

  • FFMPEG-PHP Error "Sample rate index in program config element does not match the sample rate index configured by the container."

    21 novembre 2020, par Jonathan

    Am using FFMPEG installed on a Windows server. I have a PHP webpage that uploads and trims videos using FFMPEG, when I upload MP4's with AAC audio, especially videos over 100mb, I get the following errors in the log output below.

    


    I was wondering if anyone could point me in the right direction to getting this resolved.

    


    Log output of the error below :

    


    <pre>object(FFMpeg\Exception\RuntimeException)#35 (7) {&#xA;  ["message":protected]=>&#xA;  string(15) "Encoding failed"&#xA;  ["string":"Exception":private]=>&#xA;  string(0) ""&#xA;  ["code":protected]=>&#xA;  int(0)&#xA;  ["file":protected]=>&#xA;  string(108) "C:\inetpub\wwwroot\dev\ffmpeg-lib\ffmpeg-php\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\Media\AbstractVideo.php"&#xA;  ["line":protected]=>&#xA;  int(106)&#xA;  ["trace":"Exception":private]=>&#xA;  array(1) {&#xA;    [0]=>&#xA;    array(5) {&#xA;      ["file"]=>&#xA;      string(45) "C:\inetpub\wwwroot\dev\ffmpeg-lib\process.php"&#xA;      ["line"]=>&#xA;      int(35)&#xA;      ["function"]=>&#xA;      string(4) "save"&#xA;      ["class"]=>&#xA;      string(26) "FFMpeg\Media\AbstractVideo"&#xA;      ["type"]=>&#xA;      string(2) "->"&#xA;    }&#xA;  }&#xA;  ["previous":"Exception":private]=>&#xA;  object(Alchemy\BinaryDriver\Exception\ExecutionFailureException)#43 (9) {&#xA;    ["command":protected]=>&#xA;    string(393) "C:\ffmpeg\bin\ffmpeg.exe -y -ss 00:00:17.00 -i "temp/temp_20201110-100656_1080p-220mb.mp4" -t 00:00:52.00 -threads 12 -vcodec libx264 -acodec aac -b:v 1000k -refs 6 -coder 1 -sc_threshold 40 -flags &#x2B;loop -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -trellis 1 -b:a 128k -pass 1 -passlogfile "W:/TempIIS\ffmpeg-passes5fabd8bdf3612uvd6b/pass-5fabd8bdf378b" "temp/20201111-122741.mp4""&#xA;    ["errorOutput":protected]=>&#xA;    string(830102) "ffmpeg version git-2020-08-31-4a11a6f Copyright (c) 2000-2020 the FFmpeg developers&#xA;  built with gcc 10.2.1 (GCC) 20200805&#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-libsrt --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-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --enable-libsvtav1 --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf&#xA;  libavutil      56. 58.100 / 56. 58.100&#xA;  libavcodec     58.101.101 / 58.101.101&#xA;  libavformat    58. 51.101 / 58. 51.101&#xA;  libavdevice    58. 11.101 / 58. 11.101&#xA;  libavfilter     7. 87.100 /  7. 87.100&#xA;  libswscale      5.  8.100 /  5.  8.100&#xA;  libswresample   3.  8.100 /  3.  8.100&#xA;  libpostproc    55.  8.100 / 55.  8.100&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;temp/temp_20201110-100656_1080p-220mb.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : mp42&#xA;    minor_version   : 19529854&#xA;    compatible_brands: mp42isom&#xA;    creation_time   : 2016-04-11T06:32:53.000000Z&#xA;  Duration: 00:02:25.98, start: 0.000000, bitrate: 13772 kb/s&#xA;    Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)&#xA;    Metadata:&#xA;      creation_time   : 2016-04-11T06:32:53.000000Z&#xA;      handler_name    : Sound Media Handler&#xA;    Stream #0:1(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 13639 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)&#xA;    Metadata:&#xA;      creation_time   : 2016-04-11T06:32:53.000000Z&#xA;      handler_name    : Video Media Handler&#xA;      encoder         : AVC Coding&#xA;Stream mapping:&#xA;  Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))&#xA;  Stream #0:0 -> #0:1 (aac (native) -> aac (native))&#xA;Press [q] to stop, [?] for help&#xA;[aac @ 000001fc5a9ce8c0] Sample rate index in program config element does not match the sample rate index configured by the container.&#xA;[h264 @ 000001fc5a3dac80] Invalid NAL unit size (-360624822 > 108076).&#xA;[h264 @ 000001fc5a3dac80] Error splitting the input into NAL units.&#xA;[aac @ 000001fc5a9ce8c0] Inconsistent channel configuration.&#xA;[aac @ 000001fc5a9ce8c0] get_buffer() failed&#xA;Error while decoding stream #0:0: Invalid argument&#xA;[aac @ 000001fc5a9ce8c0] Sample rate index in program config element does not match the sample rate index configured by the container.&#xA;[aac @ 000001fc5a9ce8c0] Inconsistent channel configuration.&#xA;[aac @ 000001fc5a9ce8c0] get_buffer() failed&#xA;Error while decoding stream #0:0: Invalid argument&#xA;[aac @ 000001fc5a9ce8c0] channel element 2.15 is not allocated&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] Sample rate index in program config element does not match the sample rate index configured by the container.&#xA;[aac @ 000001fc5a9ce8c0] Inconsistent channel configuration.&#xA;[aac @ 000001fc5a9ce8c0] get_buffer() failed&#xA;Error while decoding stream #0:0: Invalid argument&#xA;[h264 @ 000001fc5a3be480] Invalid NAL unit size (1926587749 > 39711).&#xA;[h264 @ 000001fc5a3be480] Error splitting the input into NAL units.&#xA;[h264 @ 000001fc5a3e4540] Invalid NAL unit size (-1483385910 > 21666).&#xA;[h264 @ 000001fc5a3e4540] Error splitting the input into NAL units.&#xA;[h264 @ 000001fc5ad06500] Invalid NAL unit size (1060193647 > 41388).&#xA;[h264 @ 000001fc5ad06500] Error splitting the input into NAL units.&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[h264 @ 000001fc5ad22e80] Invalid NAL unit size (1499431567 > 26513).&#xA;[h264 @ 000001fc5ad22e80] Error splitting the input into NAL units.&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[h264 @ 000001fc5a3dac80] Invalid NAL unit size (-23485766 > 46738).&#xA;[h264 @ 000001fc5a3dac80] Error splitting the input into NAL units.&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[h264 @ 000001fc5a3be480] Invalid NAL unit size (2023411154 > 21613).&#xA;[h264 @ 000001fc5a3be480] Error splitting the input into NAL units.&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[h264 @ 000001fc5a3e4540] Invalid NAL unit size (519125029 > 48521).&#xA;[h264 @ 000001fc5a3e4540] Error splitting the input into NAL units.&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[h264 @ 000001fc5ad06500] Invalid NAL unit size (-2099015076 > 25631).&#xA;[h264 @ 000001fc5ad06500] Error splitting the input into NAL units.&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[h264 @ 000001fc5ad22e80] Invalid NAL unit size (-1081182476 > 46590).&#xA;[h264 @ 000001fc5ad22e80] Error splitting the input into NAL units.&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] channel element 2.0 is not allocated&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] Multiple frames in a packet.&#xA;[aac @ 000001fc5a9ce8c0] Sample rate index in program config element does not match the sample rate index configured by the container.&#xA;[h264 @ 000001fc5a3dac80] Invalid NAL unit size (-2080403149 > 27914).&#xA;[h264 @ 000001fc5a3dac80] Error splitting the input into NAL units.&#xA;[aac @ 000001fc5a9ce8c0] Inconsistent channel configuration.&#xA;[aac @ 000001fc5a9ce8c0] get_buffer() failed&#xA;Error while decoding stream #0:0: Invalid argument&#xA;[aac @ 000001fc5a9ce8c0] Sample rate index in program config element does not match the sample rate index configured by the container.&#xA;[aac @ 000001fc5a9ce8c0] Inconsistent channel configuration.&#xA;[aac @ 000001fc5a9ce8c0] get_buffer() failed&#xA;Error while decoding stream #0:0: Invalid argument&#xA;[aac @ 000001fc5a9ce8c0] channel element 3.9 is not allocated&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] Reserved bit set.&#xA;[aac @ 000001fc5a9ce8c0] Prediction is not allowed in AAC-LC.&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] channel element 2.6 is not allocated&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] Number of scalefactor bands in group (52) exceeds limit (49).&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] channel element 3.10 is not allocated&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] channel element 2.13 is not allocated&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] channel element 3.8 is not allocated&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] Reserved bit set.&#xA;[aac @ 000001fc5a9ce8c0] Prediction is not allowed in AAC-LC.&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] channel element 3.9 is not allocated&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] Number of bands (50) exceeds limit (49).&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] Sample rate index in program config element does not match the sample rate index configured by the container.&#xA;[aac @ 000001fc5a9ce8c0] Inconsistent channel configuration.&#xA;[aac @ 000001fc5a9ce8c0] get_buffer() failed&#xA;Error while decoding stream #0:0: Invalid argument&#xA;[aac @ 000001fc5a9ce8c0] Reserved bit set.&#xA;[aac @ 000001fc5a9ce8c0] Number of bands (17) exceeds limit (13).&#xA;Error while decoding stream #0:0: Invalid data found when processing input&#xA;[aac @ 000001fc5a9ce8c0] Sample rate index in program config element does not match the sample rate index configured by the container.&#xA;[aac @ 000001fc5a9ce8c0] Inconsistent channel configuration.&#xA;[aac @ 000001fc5a9ce8c0] get_buffer() failed&#xA;Error while decoding stream #0:0: Invalid argument&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[h264 @ 000001fc5a3be480] Invalid NAL unit size (-296706614 > 48346).&#xA;[h264 @ 000001fc5a3be480] Error splitting the input into NAL units.&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[h264 @ 000001fc5a3e4540] Invalid NAL unit size (-1419758286 > 23497).&#xA;[h264 @ 000001fc5a3e4540] Error splitting the input into NAL units.&#xA;Error while decoding stream #0:1: Invalid data found when processing input&#xA;[h264 @ 000001fc5ad06500] Invalid NAL unit size (86578229 > 53255).&#xA;[h264 @ 000001fc5ad06500] Error splitting the input into NAL units.&#xA;</pre>

    &#xA;

  • How do i properly setup ffmpeg and fix this "Permission Denied" error im getting ?

    8 décembre 2020, par ExaNori

    Error im getting&#xA;C:/Users/Motzumoto/Desktop/AGB/ffmpeg/bin: Permission denied

    &#xA;

    I already have ffmpeg installed to path on my windows 10 machine, but that didnt fix it, so i just tried to put ffmpeg in my bots directory, that didnt do it either.&#xA;Heres my music code if anyone can help&#xA;It uses a mixture of youtube-dl and ffmpeg&#xA;If there are also any errors that would stop this from working at all it'd be nice if you could show me them, im quite tired of this as of now and im honestly just about to scrap this idea and forget about it

    &#xA;

    I've tried linking the path to the ffmpeg.exe, that still didnt work, i got the same error, i have no idea what to do

    &#xA;

    import asyncio&#xA;import logging&#xA;import math&#xA;from urllib import request&#xA;&#xA;import discord&#xA;from discord.ext import commands&#xA;import youtube_dl&#xA;from utils.guilds import Guilds&#xA;import ffmpeg&#xA;from asyncio import run_coroutine_threadsafe as coroutine&#xA;&#xA;DOWNLOAD_PATH = "audio" # download path of the file&#xA;STREAM_INDICATOR_PREFIX = "${STREAM}:"&#xA;&#xA;&#xA;&#xA;&#xA;# options&#xA;ytdl_options = {&#xA;    "quiet": True,&#xA;    "forceipv4": True,&#xA;    "noplaylist": True,&#xA;    "no_warnings": True,&#xA;    "ignoreerrors": True,&#xA;    "nooverwrites": True,&#xA;    "restrictfilenames": True,&#xA;    "nocheckcertificate": True,&#xA;    "default_search": "auto",&#xA;    "format": "bestaudio/best",&#xA;}&#xA;ffmpeg_options = {&#xA;    "options": "-vn" # indicates that we have disabled video recording in the output file&#xA;}&#xA;&#xA;ytdl = youtube_dl.YoutubeDL(ytdl_options) # youtube_dl object&#xA;&#xA;# checks functions&#xA;def is_connected(ctx):&#xA;    """Check if the bot is connected to a voice channel."""&#xA;    &#xA;    if ctx.voice_client:&#xA;        return True&#xA;    &#xA;    return False&#xA;def is_same_channel(ctx):&#xA;    """Check if the bot and the user is in the same channel."""&#xA;    &#xA;    # try to get their voice channel id if there&#x27;s any&#xA;    try:&#xA;        bot_channel_id = ctx.voice_client.channel.id&#xA;        user_channel_id = ctx.author.voice.channel.id&#xA;    # if one of them is not connected to a voice channel then they&#x27;re not together&#xA;    except AttributeError:&#xA;        return False&#xA;    &#xA;    # check if their voice channel id is the same&#xA;    if bot_channel_id == user_channel_id:&#xA;        return True&#xA;    &#xA;    return False&#xA;async def checks(ctx):&#xA;    """Do some checking."""&#xA;    &#xA;    # check if the user and the bot is in the same channel&#xA;    if not is_same_channel(ctx):&#xA;        await ctx.send("I am not with you. How dare you to command me like that.")&#xA;        return False&#xA;    &#xA;    return True&#xA;&#xA;# other function&#xA;async def create_source(ctx, query):&#xA;    """Creates youtube_dl audio source for discord.py voice client."""&#xA;    &#xA;    try:&#xA;        async with ctx.typing(): # shows that the bot is typing in chat while searching for an audio source&#xA;            source = await YTDLSource.from_url(query, ctx.bot.loop) # creates a youtube_dl source&#xA;    except IndexError: # if found nothing&#xA;        await ctx.send("I found nothing with the given query..")&#xA;        return None&#xA;    &#xA;    return source&#xA;&#xA;class Music(commands.Cog, name="music"):&#xA;    def __init__(self, bot):&#xA;        self.bot = bot&#xA;        self.guilds = Guilds() # collection of some guilds that this bot is currently in&#xA;    &#xA;    async def cog_command_error(self, ctx, error):&#xA;        """Catch all errors of this cog."""&#xA;        &#xA;        # a check on a command has failed&#xA;        if isinstance(error, commands.CheckFailure):&#xA;            await ctx.send("I&#x27;m not connected to any voice channel.")&#xA;        # ignore this error because it is already handled at the command itself&#xA;        elif isinstance(error, commands.errors.BadArgument):&#xA;            pass&#xA;        # otherwise, log all the other errors&#xA;        else:&#xA;            music_logger.exception(error)&#xA;            await ctx.send(error)&#xA;    &#xA;    @commands.command()&#xA;    async def join(self, ctx):&#xA;        """Invite me to your voice channel."""&#xA;        &#xA;        try:&#xA;            async with ctx.typing(): # shows that the bot is typing in chat while joining the voice channel&#xA;                await ctx.author.voice.channel.connect()&#xA;                await ctx.send("Alright, I joined your voice channel.")&#xA;        # user is not yet connected to a voice channel&#xA;        except AttributeError:&#xA;            await ctx.send(f"You must be connected to a voice channel first {ctx.author.name}.")&#xA;        # bot is already connected to a voice channel&#xA;        except discord.ClientException:&#xA;            if is_same_channel(ctx):&#xA;                await ctx.send("I&#x27;m already with you.")&#xA;            else:&#xA;                await ctx.send("I&#x27;m already with somebody else.")&#xA;    &#xA;    @commands.command()&#xA;    @commands.check(is_connected)&#xA;    async def leave(self, ctx):&#xA;        """Kick me out of your voice channel."""&#xA;        &#xA;        # do some checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        # reset some bot&#x27;s states&#xA;        self.guilds(ctx).has_played_voice = False # reset &#x27;has_played_voice&#x27; state&#xA;        self.guilds(ctx).queue.clear() # reset the queue&#xA;        &#xA;        # finally, stop and disconnect the bot&#xA;        ctx.voice_client.stop() # stop the bot&#x27;s voice&#xA;        await ctx.voice_client.disconnect() # disconnect the bot from voice channel&#xA;        await ctx.send("Ah, alright, cya.")&#xA;    &#xA;    async def play_source(self, ctx, vc, source):&#xA;        """Play an audio to a voice channel."""&#xA;        &#xA;        def play_next(error):&#xA;            """Executes when the voice client is done playing."""&#xA;            &#xA;            # log the errors if there is any&#xA;            if error:&#xA;                music_logger.exception(error)&#xA;                coroutine(ctx.send(error), self.bot.loop)&#xA;            &#xA;            # ensure that there is a song in queue&#xA;            if self.guilds(ctx).queue.queue:&#xA;                coroutine(ctx.invoke(self.bot.get_command("next")), self.bot.loop) # go to the next song&#xA;        &#xA;        vc.play(source, after=play_next) # play the voice to the voice channel&#xA;        await ctx.send(f"Now playing &#x27;{source.title}&#x27;.")&#xA;    &#xA;    @commands.command(aliases=("p", "stream"))&#xA;    async def play(self, ctx, *, query=""):&#xA;        """Play a song for you."""&#xA;        &#xA;        # check if the query argument is empty&#xA;        if not query:&#xA;            # if yes, cancel this command&#xA;            await ctx.send("What should I play?")&#xA;            return&#xA;        &#xA;        # check if this command is invoked using &#x27;stream&#x27; alias&#xA;        if ctx.invoked_with == "stream":&#xA;            SIP = STREAM_INDICATOR_PREFIX # put prefix to the title of the source that indicates that it must be streamed&#xA;        else:&#xA;            SIP = ""&#xA;        &#xA;        # ensure that the bot is connected a voice channel&#xA;        try:&#xA;            # connect the bot to the user voice channel&#xA;            await ctx.author.voice.channel.connect()&#xA;        except AttributeError:&#xA;            # user is not yet connected to a voice channel&#xA;            await ctx.send(f"You must be connected to a voice channel first {ctx.author.name}.")&#xA;            return&#xA;        except discord.ClientException:&#xA;            pass # just ignore if bot is already connected to the voice channel&#xA;        &#xA;        # do some other checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        # create the audio source&#xA;        source = await create_source(ctx, SIP &#x2B; query)&#xA;        &#xA;        # ensure that there is actually a source&#xA;        if source:&#xA;            # initialize bot&#x27;s states if the the queue is still empty&#xA;            if not self.guilds(ctx).queue.queue:&#xA;                self.guilds(ctx).has_played_voice = True # this means that the bot has played in the voice at least once&#xA;                self.guilds(ctx).queue.enqueue(SIP &#x2B; source.title)&#xA;            &#xA;            # play the audio&#xA;            try:&#xA;                await self.play_source(ctx, ctx.voice_client, source)&#xA;            # enqueue the source if audio is already playing&#xA;            except discord.ClientException:&#xA;                self.guilds(ctx).queue.enqueue(SIP &#x2B; source.title)&#xA;                await ctx.send(f"&#x27;{source.title}&#x27; is added to the queue.")&#xA;    &#xA;    @commands.command()&#xA;    @commands.check(is_connected)&#xA;    async def volume(self, ctx, *, vol=None):&#xA;        """Adjust my voice volume."""&#xA;        &#xA;        # do some checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        vc = ctx.voice_client # get the voice client&#xA;        &#xA;        # ensure that the bot is playing voice in order to change the volume&#xA;        if not self.guilds(ctx).has_played_voice:&#xA;            await ctx.send("I haven&#x27;t even started yet.")&#xA;            return&#xA;        elif vc.source is None:&#xA;            await ctx.send("I am not playing anything.")&#xA;            return&#xA;        &#xA;        # check if user has passed an argument&#xA;        if vol is None:&#xA;            await ctx.send("I expect an argument from 0 to 100.")&#xA;            return&#xA;        &#xA;        # cast string argument &#x27;vol&#x27; into a float&#xA;        try:&#xA;            vol = float(vol)&#xA;        # except if the argument is not a number&#xA;        except ValueError:&#xA;            await ctx.send("The argument must only be a number.")&#xA;            return&#xA;        &#xA;        # set the volume&#xA;        if vol >= 0 and vol &lt;= 100: # bound the volume from 0 to 100&#xA;            vc.source.volume = vol / 100&#xA;        else:&#xA;            await ctx.send("I expect a value from 0 to 100.")&#xA;    &#xA;    @commands.command()&#xA;    @commands.check(is_connected)&#xA;    async def pause(self, ctx):&#xA;        """Pause the song."""&#xA;        &#xA;        # do some checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        vc = ctx.voice_client # get the voice client&#xA;        &#xA;        # ensure that the bot&#x27;s voice is playing in order to pause&#xA;        if vc.is_playing():&#xA;            vc.pause()&#xA;            await ctx.send("Alright, paused.")&#xA;        # the bot haven&#x27;t played yet&#xA;        elif not self.guilds(ctx).has_played_voice:&#xA;            await ctx.send("I haven&#x27;t even started yet.")&#xA;        # there is no song in queue&#xA;        elif not self.guilds(ctx).queue.queue:&#xA;            await ctx.send("I am not playing anything.")&#xA;        else:&#xA;            await ctx.send("I already paused.")&#xA;    &#xA;    @commands.command()&#xA;    @commands.check(is_connected)&#xA;    async def resume(self, ctx):&#xA;        """Resume the song."""&#xA;        &#xA;        # do some checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        vc = ctx.voice_client # get the voice client&#xA;        &#xA;        # ensure that the bot&#x27;s voice is paused in order to resume&#xA;        if vc.is_paused():&#xA;            vc.resume()&#xA;            await ctx.send("Alright, song resumed")&#xA;        # the bot haven&#x27;t played yet&#xA;        elif not self.guilds(ctx).has_played_voice:&#xA;            await ctx.send("I haven&#x27;t even started yet.")&#xA;        # there is no song in queue&#xA;        elif not self.guilds(ctx).queue.queue:&#xA;            await ctx.send("I am not playing anything.")&#xA;        else:&#xA;            await ctx.send("I am not paused.")&#xA;    &#xA;    async def update_song(self, ctx):&#xA;        """Change the currently playing song."""&#xA;        &#xA;        vc = ctx.voice_client # get the voice client&#xA;        current = self.guilds(ctx).queue.current # get the current song in queue if there&#x27;s any&#xA;        &#xA;        # ensure that the queue is not empty&#xA;        if current:&#xA;            source = await create_source(ctx, current) # create the audio source&#xA;        # the bot haven&#x27;t played yet&#xA;        elif not self.guilds(ctx).has_played_voice:&#xA;            await ctx.send("I haven&#x27;t even started yet.")&#xA;            return&#xA;        else:&#xA;            vc.stop() # stop the voice just to be sure&#xA;            await ctx.send("No more songs unfortunately.")&#xA;            return&#xA;        &#xA;        # if voice client is already playing, just change the source&#xA;        if vc.is_playing():&#xA;            vc.source = source&#xA;            await ctx.send(f"Now playing &#x27;{source.title}&#x27;.")&#xA;        # otherwise, play the source&#xA;        else:&#xA;            await self.play_source(ctx, vc, source)&#xA;    &#xA;    @commands.command()&#xA;    @commands.check(is_connected)&#xA;    async def next(self, ctx):&#xA;        """Skip the current song."""&#xA;        &#xA;        # do some checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        self.guilds(ctx).queue.shift(1) # shift the queue to the left&#xA;        await self.update_song(ctx) # change the current song&#xA;    &#xA;    @commands.command()&#xA;    @commands.check(is_connected)&#xA;    async def prev(self, ctx):&#xA;        """Go back to the previous song."""&#xA;        &#xA;        # do some checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        self.guilds(ctx).queue.shift(-1) # shift the queue to the right&#xA;        await self.update_song(ctx) # change the current song&#xA;    &#xA;    @commands.command()&#xA;    @commands.check(is_connected)&#xA;    async def removesong(self, ctx, *, index=1):&#xA;        """Remove a song in the queue."""&#xA;        &#xA;        # do some checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        index -= 1 # decrement the &#x27;index&#x27; to match the zero-based index of Python&#xA;        &#xA;        # if index is equal to 0, that means remove the currently playing song&#xA;        # do some extra stuff before removing the current song&#xA;        if index == 0:&#xA;            # try to remove a song in queue&#xA;            try:&#xA;                self.guilds(ctx).queue.dequeue() # dequeue a song in the queue&#xA;                self.guilds(ctx).queue.shift(-1) # shift the queue to the right so that the next song will be played instead of the next next song&#xA;                await ctx.invoke(self.bot.get_command("next")) # finally, play the next song&#xA;            # except when the queue is empty&#xA;            except IndexError:&#xA;                await ctx.send("I haven&#x27;t even started yet.")&#xA;        # otherwise, just remove a song in queue&#xA;        else:&#xA;            # try to remove the song in queue&#xA;            try:&#xA;                self.guilds(ctx).queue.pop(index)&#xA;                await ctx.send("Song removed")&#xA;            # except if the song is not in the queue&#xA;            except IndexError:&#xA;                # check if the bot has not started playing yet&#xA;                if not self.guilds(ctx).has_played_voice:&#xA;                    await ctx.send("I haven&#x27;t even started yet...")&#xA;                else:&#xA;                    await ctx.send(f"I can&#x27;t remove that {ctx.author.name} because it doesn&#x27;t exist.")&#xA;    @removesong.error&#xA;    async def remove_error(self, ctx, error):&#xA;        """Error handler for the &#x27;remove&#x27; command."""&#xA;        &#xA;        # check if the argument is bad&#xA;        if isinstance(error, commands.errors.BadArgument):&#xA;            await ctx.send(f"I can&#x27;t remove that {ctx.author.name}.")&#xA;            await ctx.send("The argument must only be a number or leave it none.")&#xA;    &#xA;    @commands.command()&#xA;    @commands.check(is_connected)&#xA;    async def stop(self, ctx):&#xA;        """Stop all the songs."""&#xA;        &#xA;        # do some checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        vc = ctx.voice_client # get the voice client&#xA;        &#xA;        # ensure that the bot is connected to the voice client&#xA;        if vc.is_playing() or vc.is_paused():&#xA;            self.guilds(ctx).queue.clear() # reset the queue&#xA;            ctx.voice_client.stop() # stop the bot&#x27;s voice&#xA;            await ctx.send("Playback stopped")&#xA;        # the bot haven&#x27;t played yet&#xA;        elif not self.guilds(ctx).has_played_voice:&#xA;            await ctx.send("I haven&#x27;t even started yet.")&#xA;        else:&#xA;            await ctx.send("I already stopped.")&#xA;    &#xA;    @commands.command()&#xA;    @commands.check(is_connected)&#xA;    async def queue(self, ctx):&#xA;        """Show the queue of songs."""&#xA;        &#xA;        SIP = STREAM_INDICATOR_PREFIX # shorten the variable name&#xA;        &#xA;        # do some checking before executing this command&#xA;        if not await checks(ctx):&#xA;            return&#xA;        &#xA;        # try to send the songs in the queue&#xA;        try:&#xA;            # format the queue to make it readable&#xA;            queue = [&#xA;                f"{i}." &#x2B; (" (STREAM) " if q.startswith(SIP) else " ") &#x2B; q.split(SIP)[-1]&#xA;                for i, q in enumerate(self.guilds(ctx).queue.queue, 1)&#xA;            ]&#xA;            &#xA;            await ctx.send("\n".join(queue))&#xA;        # except if it is empty&#xA;        except HTTPException:&#xA;            await ctx.send("No songs in queue.")&#xA;&#xA;class YTDLSource(discord.PCMVolumeTransformer):&#xA;    """Creates a youtube_dl audio source with volume control."""&#xA;    &#xA;    def __init__(self, source, *, data, volume=1):&#xA;        super().__init__(source, volume)&#xA;        self.data = data&#xA;        self.title = data.get("title")&#xA;        self.url = data.get("url")&#xA;    &#xA;    @classmethod&#xA;    async def from_url(cls, url, loop):&#xA;        """Get source by URL."""&#xA;        &#xA;        # check if the URL is must be streamed&#xA;        if url.startswith(STREAM_INDICATOR_PREFIX):&#xA;            stream = True&#xA;        else:&#xA;            stream = False&#xA;        &#xA;        # get data from the given URL&#xA;        data = await loop.run_in_executor(&#xA;            None,&#xA;            (lambda:&#xA;                ytdl.extract_info(&#xA;                    url.split(STREAM_INDICATOR_PREFIX)[-1], # remove the prefix from the URL&#xA;                    download=not stream&#xA;                ))&#xA;        )&#xA;        ##$$$$ fix error somtimes&#xA;        # take the first item from the entries if there&#x27;s any&#xA;        if "entries" in data:&#xA;            try:&#xA;                data = data["entries"][0]&#xA;            except Exception as e:&#xA;                music_logger.exception(e)&#xA;                return None&#xA;        &#xA;        filepath = data["url"] if stream else ytdl.prepare_filename(data) # source url or download path of the file, depends on the &#x27;stream&#x27; parameter&#xA;        return cls(discord.FFmpegPCMAudio("C:/Users/Motzumoto/Desktop/AGB/ffmpeg/bin", **ffmpeg_options), data=data) # create and return the source&#xA;&#xA;def setup(bot):&#xA;    bot.add_cog(Music(bot))&#xA;&#xA;

    &#xA;

  • Google Speech API "Sample rate in request does not match FLAC header"

    13 février 2017, par kjdion84

    I’m trying to convert an mp4 video clip into a FLAC audio file and then have google speech spit out the words from the video so that I can detect if specific words were said.

    I have everything working except that I am getting an error from the Speech API :

    {
     "error": {
       "code": 400,
       "message": "Sample rate in request does not match FLAC header.",
       "status": "INVALID_ARGUMENT"
     }
    }

    I am using FFMPEG in order to convert the mp4 into a FLAC file. I am specifying that the FLAC file be 16 bits in the command, but when I right click on the FLAC file Windows is telling me it is 302kbps.

    Here is my PHP code :

    // convert mp4 video to 16 bit flac audio file
    $cmd = 'C:/wamp/www/ffmpeg/bin/ffmpeg.exe -i C:/wamp/www/test.mp4 -c:a flac -sample_fmt s16 C:/wamp/www/test.flac';
    exec($cmd, $output);

    // convert flac to text so we can detect if certain words were said
    $data = array(
       "config" => array(
           "encoding" => "FLAC",
           "sampleRate" => 16000,
           "languageCode" => "en-US"
       ),
       "audio" => array(
           "content" => base64_encode(file_get_contents("test.flac")),
       )
    );

    $json_data = json_encode($data);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=MY_API_KEY');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $result = curl_exec($ch);