Re: [Py4j-users] Question about Python bytearray and Java byte[]
Status: Beta
Brought to you by:
barthe
From: <kur...@co...> - 2012-10-14 20:13:37
|
Hi Bartelemy, Ok I'll check it out, thanks! ----- Original Message ----- From: "Barthelemy Dagenais" <ba...@cs...> To: "Support and Comments about Py4J" <py4...@li...> Sent: Sunday, October 14, 2012 12:54:23 PM Subject: Re: [Py4j-users] Question about Python bytearray and Java byte[] Hi Kurt, Quick question before I start looking into this in more details: which version of Py4J are you using and which version of Python? There has been **a lot** of work after the latest official release on getting bytearray work correctly. The previous implementation (0.7) was buggy and did not handle bytes that looked like surrogates. You can try the latest version by using the jar file and the tar.gz package found here: https://github.com/bartdag/py4j/tree/master/current-release Although you will see 0.7 in the version, it contains all the bugfixes pushed after the 0.7 release. Thanks, Barthelemy On Sun, Oct 14, 2012 at 3:25 PM, <kur...@co...> wrote: > Hello all, > > First off I want to say thanks to the developers of this project. We are a > python shop using py4j to work with a vendor that provides us .class and .so > library interfaces. For our Mac and Windows developers we use the py4j > package to talk to the .class driver otherwise we use Python's ctypes to > interact with their native unix .so library. > > So my question relates to bytearrays in Python. I have a straightforward > Gateway java class attached below that interacts with our vendor's code. In > red I've highlighted where my issues are. On the python side I'm doing > this: > > code = gateway.ttsRequestBuffer(self.server_ip, self.server_port, text, > self.voice, fmt, bFirst, bAll) > > buf = self.gw.ttsGetBufferData() if (code == > driver_h.TTS_RESULT_SUCCESS) else None > > > buf is a Python bytearray. The Java Gateway is returning byte[] which in > this case is the binary of a short .wav clip. Attached are two files, each > one is the hexdump of the short .wav file. The unix one is generated by > using Python's ctype library and the Java uses py4j to talk to our vendor's > library. > > > Java using py4j: > > 00000000 52 49 46 46 00 1c 02 00 57 41 56 45 66 6d 74 20 |RIFF....WAVEfmt > | > > 00000010 12 00 00 00 01 00 01 00 40 1f 00 00 80 3e 00 00 > |........@....>..| > > > Unix using ctypes: > > 00000000 52 49 46 46 da 1c 02 00 57 41 56 45 66 6d 74 20 |RIFF....WAVEfmt > | > > 00000010 12 00 00 00 01 00 01 00 40 1f 00 00 80 3e 00 00 > |........@....>..| > > > These are the first 32 bytes of the files. This occurs throughout and > doesn't seem to be random, take a look at the file differences between the > two attachments, it's very strange. And I did test writeToTempfile() to > verify it wasn't on the Java side. The problem definitely is between > returning the byte[] buffer on the Java side and the reading of that > bytearray on Python side. > > We would love to get this working so our Mac and Windows developers can work > with our vendor's library. > > Any ideas would be helpful, > Thanks! > Kurt > > > ******************************* > > > import java.lang.String; > > import java.io.IOException; > > > import py4j.GatewayServer; > > import voiceware.libttsapi; // This is our vendors library > > > class Gateway > > { > > private libttsapi m_ttsapi; > > > /* Default c'tor create libttsapi instance used by our gateway to > > * communicate with our python app */ > > public Gateway() > > { > > m_ttsapi = new libttsapi(); > > } > > > > /* python client will call this and get socket error if gateway not up > */ > > public boolean get_gw_status() > > { > > return true; > > } > > > /* server status port is default to 7777 */ > > public int ttsRequestStatus(String ipaddr, int status_port) > > { > > int rc; > > try > > { > > rc = m_ttsapi.ttsRequestStatus(ipaddr, status_port); > > } > > catch (IOException e) > > { > > rc = -9; > > } > > return rc; > > } > > > /* request to generate buffer from tts server */ > > public int ttsRequestBuffer(String ipaddr, int port, String text, int > speakerId, > > int bufformat, int reqfirst, int oneframe) > > { > > int rc; > > try > > { > > rc = m_ttsapi.ttsRequestBuffer(ipaddr, port, text, speakerId, > > bufformat, reqfirst, oneframe); > > } > > catch (IOException e) > > { > > rc = -9; > > } > > return rc; > > } > > > /* Typically after if ttsRequestBuffer() successfull to get buffer > contents */ > > public byte[] ttsGetBufferData() > > { > > return m_ttsapi.szVoiceData; > > } > > > /* main entry point for Gateway */ > > public static void main(String[] args) > > { > > GatewayServer gatewayServer = new GatewayServer(new Gateway()); > > gatewayServer.start(); > > } > > } > > > > ------------------------------------------------------------------------------ > Don't let slow site performance ruin your business. Deploy New Relic APM > Deploy New Relic app performance management and know exactly > what is happening inside your Ruby, Python, PHP, Java, and .NET app > Try New Relic at no cost today and get our sweet Data Nerd shirt too! > http://p.sf.net/sfu/newrelic-dev2dev > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > ------------------------------------------------------------------------------ Don't let slow site performance ruin your business. Deploy New Relic APM Deploy New Relic app performance management and know exactly what is happening inside your Ruby, Python, PHP, Java, and .NET app Try New Relic at no cost today and get our sweet Data Nerd shirt too! http://p.sf.net/sfu/newrelic-dev2dev _______________________________________________ Py4j-users mailing list Py4...@li... https://lists.sourceforge.net/lists/listinfo/py4j-users |