Alternate ways to play music on discord bot - python-3.x

I am currently using youtube-dl along with ffmpeg to play songs from my discord bot. However, searching for the song, downloading the video and extracting the audio takes a long time.
So I wanted to know if there is any way to speed up the process so the music can be played almost instantaneously.

You could use Lavalink then. You basically have to host a Lavalink server with your bot and it comes with logs which is really good. It handles sending the songs to discord.
https://github.com/Devoxin/Lavalink.py
You could use this as your wrapper for python

Related

blocking audio app for node.js and electron

I'm using nodejs and ubuntu 21.10. I have an electron app that has to play an mp3 file. Presently I do this by launching a system app to play the file. I want to know when the playback has finished. I have tried mplayer and mpg123. They seem to work similarly. I issue the command to play the file and the app I use, mplayer or mpg123, returns right away before the mp3 finished playing.
If you were to launch the player playing the file from the command line, the playback is acompanied by some changing textual display on the screen. I think these players play the track in a separate thread. I want something that blocks until the track is done.
The reason I want this is that I'm using the microphone immediately after the playback. I don't want the mic listening to the playback. Presently I use a timer to wait 3 seconds before going to the microphone, but that's not the best, I'm sure.
I think my code looks like this now:
const out = execSync("mpg123 ./sample.mp3");
Any help would be appreciated.

Is streaming audio from my DAW to Discord possible with a discord bot?

I found out the other day that discord bots had the ability to play audio in stereo which is not possible with a regular discord account. Maybe it could be possible to stream Ableton Live's audio output to a node.js server for a bot to play back in a Discord channel.
I found this plugin : https://listento.audiomovers.com/ which is a good starting point.
This page shows exemples of audio playback code but not live streaming methods https://discord.js.org/#/docs/main/stable/class/PlayInterface?scrollTo=play
The idea is to live stream audio without the delay that could be caused by video with a soft like OBS. And Discord would be a great platform for this as people would be able to react and make music together.
I need help with the structure of all this. Do you think this is possible ?
Have a look at https://rogueamoeba.com/audiohijack/
and it's free alternative https://github.com/mattingalls/Soundflower/releases
If you run your discord bot locally then you can just set Ableton's output to be an input for the bot using one of the above.
I agree, You can use Asio Link Pro Tool The developer gives it out for free and I use it all the time, especially when chaining audio interfaces together to get more inputs. Works great, you can check out a video with Mr. Different TV on Youtube to understand it.
https://give.academy/downloads/2018/03/03/ODeusASIOLinkPro/
https://www.youtube.com/watch?v=emRZxa0pqbs
Unlimited inputs and outputs (>:o)

Create dynamic audio broadcast stream (node, ffmpeg, ..?)

I have coded a videoboard. Like a soundboard but with video. You go to one URL that's just a black screen and another one which has a list of different videos (sender). When you click one of these videos it plays on the black screen (receiver). If you play 2 different videos at the same time both videos are shown next to each other on the receiver. That's working fine for several months now. It just creates multiple html video-elements with multiple source-tags (x265 mp4 and vp9 webm).
I recently made a discord bot which takes the webm, extracts the opus stream and plays its sound in the voice channel where the bot is connected. This has one disadvantage: It can only play one sound at a time. It happens a lot that there are multiple videos/sounds playing at the same time so this a bit of a bummer.
So I thought I should create a audiostream on the server which hosts the videoboard and just connect the bot to that stream. But I have no clue how to do this. All I know is that it's very likely going to involve ffmpeg.
What would be the best option here? What I think I would need is basically an infinite silence stream and the possibility to add a audio file onto that stream at any point which will play simultaneously with other audio files that were added before and have not ended payback yet. How is that possible? Somehow with m3u8 playlist-files or via rtsp protocol?
Thanks :)
I think it can be helpful for you https://bitbucket.org/kaleniuk_ihor/neuro_vision/src/db_watch/
Also this library was very useful for me https://github.com/kyriesent/node-rtsp-stream you can just install npm i node-rtsp-stream

Stream music from streaming platform (Deezer, Spotify, Soundcloud) to Web Audio API

Do any of you, know a way to get the audio stream of a music platform and plug it to the Web Audio API ?
I am doing a music visualizer based on the Web Audio API. It currently reads sounds from the mic of my computer and process a real-time visualization. If I play music loud enough, my viz works !
But now I'd like to move on and only read the sound coming from my computer, so that the visualization render only to the music and no other sound such as people chatting.
I know I can buffer MP3 file in that API and it would work perfectly. But in 2020, streaming music is very common, via Deezer, Spotify, Souncloud etc.
I know they all have an API but they often offer an SDK where you cannot really do more than "play" music. There is no easy access to the stream of audio data. Maybe I am wrong and that is why I ask your help.
Thanks
The way to stream music to WebAudio is to use a MediaElementAudioSourceNode or MediaStreamAudioSourceNode. However, these nodes will output zero unless you're allowed to access the data. This means you have to set the CORS property correctly on your end and also requires the server to allow the access through CORS.
A google search will help with setting up CORS. But many sites won't allow access unless you have the right permissions. Then you are out of luck.
I find a "no-code" work around. At least on Ubuntu 18.04, I am able to tell Firefox to take my speakers as the "microphone input".
You just have to select the good "mic" in the list when your browser asks for mic permission.
That solution is very convenient since I do not need to write platform-specific binding-code to access to the audio stream

music playback on Google Home

I'm trying to migrate a music player Alexa Skill to Google Home. But I cannot find a pre-built music playback (Actions or DialogFlow)... I want to reproduce streaming music using my own music server (not from Spotify or Google music).
I found a couple of examples using buildRichResponse and/or MediaObject, but these are not exactly a playback service.
Does anyone know if google home has a multimedia playback or a way to do it easily?
Thx
The Assistant's Media response is the nearest parallel to Alexa's AudioPlayer, although there are clearly differences between the two:
Alexa's playback is done outside the context of a session / conversation. So once you start a playback, you only have the playback controls available. Assistant Media controls are part of a conversation, so you can fully handle anything the user might say.
One consequence of this is that Alexa treats the playback as the result of the skill, while the Assistant treats it as part of the Action.
Google only sends an event when media playback has finished, and doesn't give any indication of why it has finished. Alexa reports more of the controls and has more events describing the state of the playback.
This makes it fairly easy to "queue up" the next audio for Alexa, but that brings additional complexity for how to handle when the queue ends up being wrong at the last moment. The Assistant doesn't have any way to queue the next audio, so there ends up being a gap between the audio ending and the next beginning while the event is handled on the server.
Although the approaches are slightly different, both seem to offer a basic long-audio playback service.
This doesn't sound like what you are trying to do, but if you are looking for something slightly more static, you can also look at the content actions that Google supports.
See https://github.com/Limag/aiplayer/ for an example to play self hosted MP3s. Unfortunately, even changing the volume will not be recognized. And it seems there is no way to add this.
If you use Google Play Music, you can upload MP3s with a tiny helper application, provided by Google. Google Play Music works well, but has some other disadvantages. E.g. it is unusable for audio books, all playlists starting always from the beginning.

Resources