python lossless audio recording+http streaming library - python

I am working on a simple service to remotely record line input from an audio interface attached to a server, via REST API request.
My current solution, using PyAudio to manage the audio interface:
1) send HTTP request to start recording to a file on server filesystem.
2) send HTTP request to stop recording and pull the recorded audio file from the server filesystem
Instead, I would like to be able to just "stream" the line input to any http client who wants to download the audio stream.
Is there any simple python library solution to lossless http audio streaming directly from any audio interface's input?
More importantly, does this make sense or should I use RTSP instead? (More than efficiency I would like to focus on being able to download the audio stream by a simple http link on a browser or even via curl or simple programmatic request, and I'll usually not have more than one connected client at a time, that's why I'd prefer to avoid RTSP.)

I have done this using Python flask to provide the REST endpoint to stream audio, and the pyfaac module to pack PCM frames into the AAC format (this format is needed for streaming). Then, for example, you use the standard HTML5 audio tag with src set to your streaming endpoint.

Related

Nuclio Streaming Contents Support? (Docker setup - Python)

Is there support for streaming back a response in Nuclio? The workflow I'm trying to achieve is to have the UI request a large file from a Nuclio function running inside a docker container and having it stream back the large file.
For example this is how Flask supports streaming contents:
https://flask.palletsprojects.com/en/2.2.x/patterns/streaming/
I can't seem to find anywhere that mentions how to have Nuclio stream back large data/file.
I do see they mention some stuff about stream triggers, but I don't know if that'll help with streaming back the response:
https://nuclio.io/docs/latest/concepts/architecture/
https://nuclio.io/docs/latest/reference/triggers/
If there's no support, would my best bet be to stream the data to some 3rd party platform and have the UI download the data/file from there?

Streaming video file from flask server to react js client

I am creating a "Youtube Clone" using Python Flask on the backend and React JS on the server side, and I currently need to stream the video from a file on the server.
This is what I currently have:
#app.route('/api/video/<string:video_id>')
def ShowVideo(video_id):
video = Video.query.filter_by(id = video_id).first() #"Video" is the video database (using SQLAlchemy)
if video is None:
return {"return":"401"} #video doesn't exist in database
#return ??
now I have the video id and path in the database, and I need to stream it over http to a React JS website
I've seen people using OpenCV to stream, and put an image in the JS client, but from what I've seen it does not work with a video file already on the computer (I can be mistaken, I'm not sure).
Another thing I've seen is using JS to send the video directly to the browser (like in this video, but I don't think this will work for my circumstances)
Does anyone have any idea?

Running python script concurrently based on trigger

What would be best way to solve following problem with Python ?
I have real-time data stream coming to my object-oriented storage from user application (json files being stored into S3 storage in Amazon).
Upon receiving of each JSON file, I have to within certain time (1s in this instance) process data in the file and generate response that is send back to the user. This data is being processed by simple Python script.
My issue is, that the real-time data stream can at the same time generate even few hundreds JSON files from user applications that I need to run trough my Python script and I don't know how to approach this the best way.
I understand, that way to tackle this would be to use trigger based Lambdas that would execute job on the top of every file once uploaded from real-time stream in server-less environment, however this option is quite expensive compared to have single server instance running and somehow triggering jobs inside.
Any advice is appreciated. Thanks.
Serverless can actually be cheaper than using a server. It is much cheaper when there are periods of no activity because you don't need to pay for a server doing nothing.
The hardest part of your requirement is sending the response back to the user. If an object is uploaded to S3, there is no easy way to send back a response and it isn't even obvious who is the user that sent the file.
You could process the incoming file and then store a response back in a similarly-named object, and the client could then poll S3 for the response. That requires the upload to use a unique name that is somehow generated.
An alternative would be for the data to be sent to AWS API Gateway, which can trigger an AWS Lambda function and then directly return the response to the requester. No server required, automatic scaling.
If you wanted to use a server, then you'd need a way for the client to send a message to the server with a reference to the JSON object in S3 (or with the data itself). The server would need to be running a web server that can receive the request, perform the work and provide back the response.
Bottom line: Think about the data flow first, rather than the processing.

Azure Speech SDK Speech to text from stream using python

I am trying to send the stream from UI to python API as stream. I need python Azure Speech logic to convert the speech to text. I am not sure about how to use pull/pusha audio input stream for speech to text
In my case I receive an audio stream from some other source. When the connection with my application is made (upon reception of the first package), a PushAudioInputStream is started. This stream pushes the data to SDK for each package that is received. The speech recognition with push stream is thus used in this case. See snippet of code below. This has worked for my case.
if newConnection:
stream = speechsdk.audio.PushAudioInputStream()
speech_recognition_with_push_stream(stream)
stream_data = base64.b64decode(data)
stream.write(stream_data)
There is a sample for using cognitive services speech sdk.
Specifically, for using it with pull stream, you may refer to: speech_recognition_with_pull_stream() , and for using it with push stream, you may refer to: speech_recognition_with_push_stream().
Hope it helps.

Server Sent Events(SSE) in Google App Engine

Does GAE support Server Sent Events (SSE)?
I tried using SSE but it did not work ,so I switched to Channel API. But still is it possible to implement SSE in GAE ?
I've been trying like crazy to pull this one off but the GAE response is being buffered and compressed.
I'll be very happy if someone has an idea how to write the code/headers so the php file is streamed.
FYI, these are the headers I'm using:
header("Content-Type: text/event-stream; charset=utf-8");
header("Accept-Encoding: identity");
header("Cache-Control: no-cache");
header("Access-Control-Allow-Origin: https://mail.google.com");
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"');
[UPDATE]
From: http://grokbase.com/t/gg/google-appengine/15623azjjf/server-sent-events-using-channels-api
What this means in practice is that your stream will not be
"keep-alive" and will close each time one response is sent. Or, if you
implement your server-sent event code server-side as most people do,
it will buffer up all of its responses and finally send them all only
when it terminates.
Please read: https://cloud.google.com/appengine/docs/php/requests#PHP_Responses
Resume: there is no way to do SSE using GAE.

Categories

Resources