diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Audio_Stream.iml b/.idea/Audio_Stream.iml new file mode 100644 index 0000000000000000000000000000000000000000..7584dbd9056b85ac2e61f682c1dd527033266217 --- /dev/null +++ b/.idea/Audio_Stream.iml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="PYTHON_MODULE" version="4"> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$"> + <excludeFolder url="file://$MODULE_DIR$/.venv" /> + </content> + <orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000000000000000000000000000000000000..0b9e4d9f2aa7e0168d24b3acd34c774c7353d557 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,21 @@ +<component name="InspectionProjectProfileManager"> + <profile version="1.0"> + <option name="myName" value="Project Default" /> + <inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true"> + <option name="myValues"> + <value> + <list size="7"> + <item index="0" class="java.lang.String" itemvalue="nobr" /> + <item index="1" class="java.lang.String" itemvalue="noembed" /> + <item index="2" class="java.lang.String" itemvalue="comment" /> + <item index="3" class="java.lang.String" itemvalue="noscript" /> + <item index="4" class="java.lang.String" itemvalue="embed" /> + <item index="5" class="java.lang.String" itemvalue="script" /> + <item index="6" class="java.lang.String" itemvalue="letters-container" /> + </list> + </value> + </option> + <option name="myCustomValuesEnabled" value="true" /> + </inspection_tool> + </profile> +</component> \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..105ce2da2d6447d11dfe32bfb846c3d5b199fc99 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ +<component name="InspectionProjectProfileManager"> + <settings> + <option name="USE_PROJECT_PROFILE" value="false" /> + <version value="1.0" /> + </settings> +</component> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..9de286525ff35cf3ec9f171ef56fd1557939f2a0 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Black"> + <option name="sdkName" value="Python 3.10" /> + </component> + <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" /> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..f3c1c963b0a07148775a0a5092ac87753ccb3598 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/Audio_Stream.iml" filepath="$PROJECT_DIR$/.idea/Audio_Stream.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000000000000000000000000000000000000..62e8c51d2b9dd1064ee11fe31f0f5a24d10693a5 --- /dev/null +++ b/main.py @@ -0,0 +1,55 @@ +from flask import Flask,Response,render_template +import pyaudio + +app=Flask(__name__,template_folder="template") + +FORMAT=pyaudio.paInt16 +CHANNELS=2 +RATE=44100 +CHUNK=1024 +RECORD_SECONDS=5 + + +audio_stream=pyaudio.PyAudio() + + +def genHeader(sampleRate, bitsPerSample, channels): + datasize = 2000*10**6 + o = bytes("RIFF",'ascii') # (4byte) Marks file as RIFF + o += (datasize + 36).to_bytes(4,'little') # (4byte) File size in bytes excluding this and RIFF marker + o += bytes("WAVE",'ascii') # (4byte) File type + o += bytes("fmt ",'ascii') # (4byte) Format Chunk Marker + o += (16).to_bytes(4,'little') # (4byte) Length of above format data + o += (1).to_bytes(2,'little') # (2byte) Format type (1 - PCM) + o += (channels).to_bytes(2,'little') # (2byte) + o += (sampleRate).to_bytes(4,'little') # (4byte) + o += (sampleRate * channels * bitsPerSample // 8).to_bytes(4,'little') # (4byte) + o += (channels * bitsPerSample // 8).to_bytes(2,'little') # (2byte) + o += (bitsPerSample).to_bytes(2,'little') # (2byte) + o += bytes("data",'ascii') # (4byte) Data Chunk Marker + o += (datasize).to_bytes(4,'little') # (4byte) Data size in bytes + return o + + +def Sound(): + bitspersample=16 + wav_hader=genHeader(RATE,bitspersample,2) + stream=audio_stream.open(format=FORMAT,channels=2,rate=RATE,input=True,input_device_index=1,frames_per_buffer=CHUNK) + first_run=True + while True: + if first_run: + data=wav_hader+stream.read(CHUNK) + first_run=False + else: + data=stream.read(CHUNK) + yield(data) + +@app.route('/') +def index(): + return render_template("Audio.html") +#Audio Endpoint +@app.route("/audio") +def audio(): + return Response(Sound()) + +app.run(host="127.0.0.1",port=5454,threaded=True) \ No newline at end of file diff --git a/template/Audio.html b/template/Audio.html new file mode 100644 index 0000000000000000000000000000000000000000..30e5bcdaf9f22fccb57f43c808621946f328fff0 --- /dev/null +++ b/template/Audio.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta http-equiv="X-UA-Compatible" content="ie=edge"> + <title>Document</title> +</head> +<body> + <audio controls autoplay> + <source src="{{ url_for('audio') }}" type="audio/x-wav;codec=pcm" > + Your browser does not support the audio element. + </audio> +</body> +</html> \ No newline at end of file