
Recherche avancée
Autres articles (83)
-
MediaSPIP 0.1 Beta version
25 avril 2011, parMediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
The zip file provided here only contains the sources of MediaSPIP in its standalone version.
To get a working installation, you must manually install all-software dependencies on the server.
If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...) -
MediaSPIP version 0.1 Beta
16 avril 2011, parMediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...) -
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
Sur d’autres sites (13851)
-
Split h.264 stream into multiple parts in python
31 janvier 2023, par BillPlayzMy objective is to split an h.264 stream into multiple parts, meaning while reading the stream from a pipe i would like to save it into x second long packages (in my case 10).


I am using a libcamera-vid subprocess on my Raspberry Pi that outputs the h.264 stream into stdout.

Might be irrelevant, depends : libcamera-vid outputs a message every frame and I am able to locate it at isFrameStopLine
To convert the stream, I use an ffmpeg subprocess, as you can see in the code below.

Imagine it like that :

Stream is running...

- Start recording to a file

- Sleep x seconds

- Finish recording to file

- Start recording a new file

- Sleep x seconds

- Finish recording the new file

- and so on...

Here is my current code, however upon running the first export succeeds, and after the second or third the ffmpeg-subprocess is terminating with the error :

pipe:: Invalid data found when processing input

And shortly after, the python process, because of the ffmpeg termination i believe.
Traceback (most recent call last): File "/home/survpi-camera/main.py", line 56, in <module> processStreamLine(readData) File "/home/survpi-camera/main.py", line 16, in processStreamLine streamInfo["process"].stdin.write(data) BrokenPipeError: [Errno 32] Broken pipe</module>


recentStreamProcesses = []
streamInfo = {
 "lastStreamStart": -1,
 "process": None
}

def processStreamLine(data):
 isInfoLine = ((data.startswith(b"[") and (b"INFO" in data)) or (data == b"Preview window unavailable"))
 isFrameStopLine = (data.startswith(b"#") and (b" fps) exp" in data))
 if ((not isInfoLine) and (not isFrameStopLine)):
 streamInfo["process"].stdin.write(data)
 
 if (isFrameStopLine):
 if (time.time() - streamInfo["lastStreamStart"] >= 10):
 print("10 seconds passed, exporting...")
 exportStream()
 createNewStream()

def createNewStream():
 streamInfo["lastStreamStart"] = time.time()
 streamInfo["process"] = subprocess.Popen([
 "ffmpeg",
 "-r","30",
 "-i","-",
 "-c","copy",("/home/survpi-camera/" + str(round(time.time())) + ".mp4")
 ],stdin=subprocess.PIPE,stderr=subprocess.STDOUT)
 print("Created new streamProcess.")

def exportStream():
 print("Exporting...")
 streamInfo["process"].stdin.close()
 recentStreamProcesses.append(streamInfo["process"])


cameraProcess = subprocess.Popen([
 "libcamera-vid",
 "-t","0",
 "--width","1920",
 "--height","1080",
 "--codec","h264",
 "--inline",
 "--listen",
 "-o","-"
],stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.STDOUT)

createNewStream()

while True:
 readData = cameraProcess.stdout.readline()
 
 processStreamLine(readData)



Thank you in advance !


-
Why do I get UnknownValueError when trying to run .recognize_google ?
21 juillet 2022, par John SmithFollowing code is meant to transcribe a long audio file to text. It is to do this piece by piece.
trimmed.wav
holds a 15-second-long piece of a longer audio file (whose path is stored infname
) :

#!/usr/bin/env python3

from subprocess import run
from sys import exit

italic = '\33[3m'
end = '\33[m'

try:
 from speech_recognition import AudioFile, Recognizer
except:
 run("pip3 install SpeechRecognition", shell=True)
 from speech_recognition import AudioFile, Recognizer

def transcribe_piece(fname, lang, stime):
 extension = fname[-3:]
 etime = stime + 15
 cmd = f"ffmpeg -ss {stime} -to {etime} -i {fname} -c copy trimmed.{extension} >/dev/null 2>&1"
 run(cmd, shell=True)
 cmd = f"ffmpeg -i trimmed.{extension} -f wav trimmed.wav >/dev/null 2>&1"
 run(cmd, shell=True)
 r = Recognizer() 
 af = AudioFile("trimmed.wav")
 with af as source:
 r.adjust_for_ambient_noise(source)
 audio = r.record(source)
 t = r.recognize_google(audio, language=lang)#UnknownValueError() speech_recognition.UnknownValueError
 print(f"{italic}{t}{end}")
 with open("of", "w") as f:
 f.write(f"{t}\n")
 run(f"rm trimmed.{extension}", shell=True) 
 run(f"rm trimmed.wav", shell=True)
 
 

fname = input("File name? Skip the path if the file is in CWD. The usage of ~ is allowed.\n")

lang = input("""Specify one of the following languages:
fr-BE, fr-CA, fr-FR, fr-CH

en-AU, en-CA, en-GH, en-HK, en-IN, en-IE, en-KE, en-NZ, en-PK, en-PH, en-SG, en-ZA, en-TZ, en-GB, en-US

es-AR, es-BO, es-BO, es-CL, es-CO, es-CR, es-DO, es-EC, es-SV, es-SV, es-GT, es-HN, es-MX, es-NI, es-PA, es-PY, es-PE, es-PR, es-ES, es-US, es-UY, es-VE\n""")


#for stime in range(0, 10000, 15):
# try:
# transcribe_piece(fname, lang, stime)
# except:
# run("shred -u trimmed.wav" , shell=True) 
 #run("shred -u trimmed.wav >/dev/null 2>&1" , shell=True) 
# exit(0)
 
for stime in range(0, 10000, 15):#this loop is only for the sake of debugging, use try/except above
 transcribe_piece(fname, lang, stime)




It gives me the following error :


Traceback (most recent call last):
 File "/home/jim/CS/SoftwareDevelopment/MySoftware/Python/speech-to-text/long-audio-to-text.py", line 61, in <module>
 transcribe_piece(fname, lang, stime)
 File "/home/jim/CS/SoftwareDevelopment/MySoftware/Python/speech-to-text/long-audio-to-text.py", line 31, in transcribe_piece
 t = r.recognize_google(audio, language=lang)
 File "/home/jim/.local/lib/python3.10/site-packages/speech_recognition/__init__.py", line 858, in recognize_google
 if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError

</module>


The said error refers to line 31, that is
t = r.recognize_google(audio, language=lang)
.
Why do I get this error ? How might I rewrite this code so that such error does not appear ?

-
Why do I get UnknownValueError() speech_recognition.UnknownValueError when trying to run .recognize_google ?
20 juillet 2022, par John SmithFollowing code is meant to transcribe a long audio file to text. It is to do this piece by piece.
trimmed.wav
holds a 15-second-long piece of a longer audio file (whose path is stored infname
) :

#!/usr/bin/env python3

from subprocess import run
from sys import exit

italic = '\33[3m'
end = '\33[m'

try:
 from speech_recognition import AudioFile, Recognizer
except:
 run("pip3 install SpeechRecognition", shell=True)
 from speech_recognition import AudioFile, Recognizer

def transcribe_piece(fname, lang, stime):
 extension = fname[-3:]
 etime = stime + 15
 cmd = f"ffmpeg -ss {stime} -to {etime} -i {fname} -c copy trimmed.{extension} >/dev/null 2>&1"
 run(cmd, shell=True)
 cmd = f"ffmpeg -i trimmed.{extension} -f wav trimmed.wav >/dev/null 2>&1"
 run(cmd, shell=True)
 r = Recognizer() 
 af = AudioFile("trimmed.wav")
 with af as source:
 r.adjust_for_ambient_noise(source)
 audio = r.record(source)
 t = r.recognize_google(audio, language=lang)#UnknownValueError() speech_recognition.UnknownValueError
 print(f"{italic}{t}{end}")
 with open("of", "w") as f:
 f.write(f"{t}\n")
 run(f"rm trimmed.{extension}", shell=True) 
 run(f"rm trimmed.wav", shell=True)
 
 

fname = input("File name? Skip the path if the file is in CWD. The usage of ~ is allowed.\n")

lang = input("""Specify one of the following languages:
fr-BE, fr-CA, fr-FR, fr-CH

en-AU, en-CA, en-GH, en-HK, en-IN, en-IE, en-KE, en-NZ, en-PK, en-PH, en-SG, en-ZA, en-TZ, en-GB, en-US

es-AR, es-BO, es-BO, es-CL, es-CO, es-CR, es-DO, es-EC, es-SV, es-SV, es-GT, es-HN, es-MX, es-NI, es-PA, es-PY, es-PE, es-PR, es-ES, es-US, es-UY, es-VE\n""")


#for stime in range(0, 10000, 15):
# try:
# transcribe_piece(fname, lang, stime)
# except:
# run("shred -u trimmed.wav" , shell=True) 
 #run("shred -u trimmed.wav >/dev/null 2>&1" , shell=True) 
# exit(0)
 
for stime in range(0, 10000, 15):#this loop is only for the sake of debugging, use try/except above
 transcribe_piece(fname, lang, stime)




It gives me the following error :


Traceback (most recent call last):
 File "/home/jim/CS/SoftwareDevelopment/MySoftware/Python/speech-to-text/long-audio-to-text.py", line 61, in <module>
 transcribe_piece(fname, lang, stime)
 File "/home/jim/CS/SoftwareDevelopment/MySoftware/Python/speech-to-text/long-audio-to-text.py", line 31, in transcribe_piece
 t = r.recognize_google(audio, language=lang)
 File "/home/jim/.local/lib/python3.10/site-packages/speech_recognition/__init__.py", line 858, in recognize_google
 if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError

</module>


The said error refers to line 31, that is
t = r.recognize_google(audio, language=lang)
.
Why do I get this error ? How might I rewrite this code so that such error does not appear ?