start MUSIC in python - python-3.x

I need source code that loads and starts music in python without importing any modules at all. Is that possible or should I try other languages like c# or c++ because every modules are written in cpython!

First off I think it depends on the type of file but if your file of choice is WAV, AU, AIFF, MP3, CSL, SD, SMP, or NIST/Sphere, you can use The Snack Sound Toolkit. I know you asked for not using a module but this is very good and can be used on a plethora of files. It works like this:
snd = Sound()
snd.read('ex1.wav')
snd.play()
Also it can also be used to show the graphical representation of the sound by this:
c = SnackCanvas()
c.pack()
c.create_waveform(0, 0, sound=snd)

Related

How to parse succesfully a utf-16le encoded jsonfile with haxe on the php target?

I have some third party application that I have to use, it generates UTF16LE encoded json files.
When I put these manually on my server and try haxe generated php to parse these files, it refuses. It seems it can't detect and convert to the encoding haxe php accepts.
I don't know where to start. Converting it on the client is an impossibility, there are too many of such files and need too frequently be parsed. So I have to use php. It would be nice if haxe has a way to convert it to the encoding it accepts. I have tried RTFM, but I so far I havent found anything that says haxe can convert it. Before I start reinventing some second wheel, I rather make sure there isn't some obvious way to it with haxe.
I am using Haxe version 4.2.1+bf9ff69
What am I overlooking? Is haxe php able to solve this, or is going native php the only option?
== SOLVED ==
As these json files do not need any emoticon support or whatever characters for non-english language, my solution was to strip everything except basic printable ASCII characters.
import sys.io.File;
import php.Syntax;
// some function body
return Syntax.code('preg_replace( "/[^[:print:]]/", "",{0})',File.getContent(_path));
I couldn't share these file on the web, because of privacy concerns. Also I discovered these files had ... wait for it - double BOM's- hacked into it.The BOM detector I threw in reported the first BOM it found happening to be UTF16LE.
Enterprise spaghetti monster probably the reason. Thought I had seen it all, but with that, one probably can't never have seen it all. The wonders of human ingenuity.
Just a blunt strip instead of making my own ludicrous code to unfudge that stuff and justice served. Hurrah.

Ean-128 python barcode generator

Is there any python library to generate ean128 barcode. I tried 'python-barcode' , but in that library there is no option for ean128.
The person who originally asked this question may not benefit from this, but this is for those who are still looking for an answer.
Note: Code-128 is not same as GS1-128
I was also stuck with this issue a few days ago, and I finally managed to find a python library which supports the GS1-128(UCC/EAN-128) barcode.
The library I am referring to is called "treepoem". Strange name I agree that's what makes it so hard to find. It is a wrapper for BWIPP library. And it has a dependency on ghostscript as well. About the name; Barcode -> Bark ode -> Tree poem.
Important links:
1) Ghostscript; download and install it and also add its "bin" and "lib" folder to
system's path variable.
https://www.ghostscript.com/download/gsdnld.html
2)treepoem
https://pypi.org/project/treepoem/
3) All-codes; here in the repository you will find all supported barcodes here.
https://github.com/adamchainz/treepoem/blob/master/treepoem/data.py
import treepoem
image = treepoem.generate_barcode(
barcode_type='gs1-128', # One of the BWIPP supported codes.
data='(01)14-digit-product-code')
image.convert('1').save('barcode.png')
I think that EAN 128 is the same thing as Code 128 (https://en.wikipedia.org/wiki/Code_128). It seems to be supported by python-barcode
There is an alternative lib with code 128

Haxe compiling to C++ and JS source

I am trying to write source code in one language and have it converted to both native c++ and JS source. Ideally the converted source should be human readable and resemble the original source as best it can. I was hoping haxe could solve this problem for me. So I code in haxescript and have it convert it to its corresponding C++ and JS source. However the examples I'm finding of haxe seems to create the final application for you. So with C++ it will use msbuild (or whatever compiler it finds) and creates the final exe for you from generated C++ code. Does haxe also create the c++ and JS source code for you to view or is it all done internally to haxe and not accessible? If it is accessible then is it possible to remove the building side of haxe so it simply creates the source code and stops?
Thanks
When you generate CPP all the intermediate files are generated and kept wherever you decide to generate your output (the path given using -cpp pathToOutput). The fact that you get an executable is probably because you are using the -main switch. That implies an entry point to your application but that is not really required and you can just pass to the command line a bunch of types that you want to have built in your output.
For JS it is very similar, a single JS file is generated and it only has an entry point if you used -main.
Regarding the other topic, does your Haxe code resembles the generated code the answer is yes, but ... some of the types (like Enum and Abstract) only exist in Haxe so they will generate code that functionally works but it might look quite different. Also Haxe has an always-on optimizer/analyzer that might mungle your code in unexpected ways (the analyzer can be disabled). I still find that it is not that difficult to figure out the Haxe source from the generated code. JS has support for source mapping which is really useful for debugging. So in the end, Haxe doesn't do anything to obfuscate your generated code but also doesn't do much to try to preserve it too strictly.

Solution for missing std::wstring support in Android NDK?

I have a game which uses std::wstring as its basic string type in thousand of places as well as doing operations with wchar_t and its functions: wcsicmp() wcslen() vsprintf(), etc.
The problem is wstring is not supported in R5c (latest ndk at the time of this writting).
I can't change the code to use std::string because of internationalization and I would be breaking the game engine which is used by many games ...
Which options do I have?
1 - Replace string and wstring with my own string classes
This would give me better platform independency, but it is ridiculous to reimplement the wheel.
I've already started with a COW implementation of strings. I need it to be COW because I use them as keys in hash_maps.
This is of course lots of work and error prone ... but it seems it is something I can do.
2 - Try to fix the NDK recompiling the STLPort with my own implementations of the wide char string functions of the C standart library (wcslen, mbstowcs ... )
This would be the preferable way ... but I have no idea how to do it :(
How do I replace a function (lets say wcslen) in the libstdc++.a or libstlport_static.a? (not sure where they are :()
And as well I'm not sure which functions I need to reimplement, I know wcslen is not working so I guess they should be all ...
3 - Do you have any other idea?
I can't wait for an official fix for this and I will have to go with option #1 if I can't realize how to do #2.
I've read somewhere that if you target 2.3 you can use wstrings, but I ought to target Android 2.1.
PS: Forgot to say I need to use STL of course, but no RTTI and I can live without exceptions.
Thanks in advance!
Try out CrystaX's NDK. It has had stl support long before the official google one. The current version (r5), which is based off the of the official ndk r5, is still beta 3, but it does have wchar_t support.
http://www.crystax.net/android/ndk-r5.php
I'm suffering from the same problem as you, but my only other thought is to load the strings via the JNI (as jstring* in native land), then convert them to UTF characters as necessary. Take a look at the available JNI string functions here:
http://download.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html#string_operations
Qt provides an excellent copy-on-write, international-friendly string implementation, QString, that is LGPLed.
You could, in theory extract it from the Qt source and use it in your own project. You will find the QString implementation in src/corelib/tools/qstring.h and .cpp in a Qt source download. You would also need the QChar, QByteArray, QAtomic, and QNamespace includes/classes (all under the corelib folder,) and you should define QT_NO_STL_WCHAR when compiling. (For this I would compile by hand or using my own script/Makefile.) Not simple, but once you get it up and running your life will be a lot simpler. It's better than reinventing the wheel, because it comes with loads of convenience functions and features.
Rather than stripping out just QString, you could also just use the QtCore module as a whole. See the android-lighthouse project for a Qt port to Android. (Also, it might be better to get your sources from there than from the above "vanilla" link, regardless of what you do.)

Linux+Language for video capture & Display

Very soon we are going to work on a project with open source s/w that does many things and one of the modules concerns with capturing live feed from a usb based camera for upto 48 hours and overwriting it in a nonstop loop. This would be going on in parallel with other operations in the application. We also have to display the captured feed of the least 48 hours to the user as a menu option.
I would like you all to suggest a suitable open source technology stack taking into account the audio/video part of the module, without this feature I can definitely use Qt to do my stuff but with this feature that becomes a difficult proposition. I have developed GUI applications with Qt on Linux platform but haven't been able to come up with something that can record and display video in an application. Qt has phonon but setting it up is a nightmare. Earlier some of you had suggest v4linux. I tried to compile the sample program capture.c on RHEL 4 machine and it gave the following errors.
usr/src/kernels/2.6.9-5.EL-i686/include/linux/videodev2.h:436: warning: no semicolon at end of struct or union
/usr/src/kernels/2.6.9-5.EL-i686/include/linux/videodev2.h:436: error: syntax error before '*' token
/usr/src/kernels/2.6.9-5.EL-i686/include/linux/videodev2.h:438: error: syntax error before '*' token
/usr/src/kernels/2.6.9-5.EL-i686/include/linux/videodev2.h:438: warning: data definition has no type or storage class
/usr/src/kernels/2.6.9-5.EL-i686/include/linux/videodev2.h:439: error: syntax error before '}' token
/usr/src/kernels/2.6.9-5.EL-i686/include/linux/videodev2.h:810: error: field `win' has incomplete type
So hit a dead end, besides I haven't come up with concrete workable examples for the same. Also the website isn't being updated frequently suggesting a stagnancy in development process.
Since the application will be graphical with menu based user interaction, it would need to use Qt or something similar to it for the graphical part. The headache is I haven't been able to figure out, how I can implement/integrate the video capture/display feature in a dummy application (my try was with Qt may be some of you have done it with some other library or language).
EDIT:
Was able to compile the program by importing a local copy of videodev2.h and adding define statement to include a __user macro. But now it won't run as it cannot find /dev/video device. So again stuck at a dead end in video4linux
You could try the FFmpeg family of libraries. As of fairly recently (I think), it also comes with the libavdevice library that supports V4L and V4L2 for video capture, and it shouldn't be very difficult to build a FFmpeg pipeline to read video from an avdevice source and write it using avcodec and avformat into a file...
gstreamer is a very capable multimedia stack for capturing, and pygst and PyQt4 bindings exist for use in Python.
If it said "can't find /dev/video", that is because Linux numbers the devices.
If you would have looked in the .c file you would have seen there were several arg_opts
as -d ... (where ... would become /dev/video0) or you can go in the .c file and add a 0 to /dev/video, you'll find it somewhere about line 590 in the beginning of int main.

Resources