©2003 Kåre Sjölander and Jonas Beskow
Introduction Download Documentation Links Forum
WaveSurfer user forum

FAQ  FAQ
Search  Search
Memberlist  Memberlist
Register  Register
Profile  Profile
Login  Login

snack python : not implemented features

 
Post new topic   Reply to topic    www.speech.kth.se/wavesurfer Forum Index -> WaveSurfer
View previous topic :: View next topic  
Author Message
edouard



Joined: 02 Feb 2004
Posts: 3

PostPosted: Tue Oct 12, 2004 5:26 pm    Post subject: snack python : not implemented features Reply with quote

Hi,

I was wondering why there are still two subcommands not implemented in python Sound object : Sound.data and Sound.append.
After some time spent on a debugger, I don't have the answer but maybe a TCL guru can help.

The data and append methods in tkSnack.py can be coded like this :
Code:

def data(self, binarydata=None, **kw):
     """Loads sound data from, or writes to, a binary string."""
     if binarydata: # copy data to sound
         self.tk.call((self.name, 'data', binarydata) + self._options(kw))
     else: # return sound data
         return self.tk.call((self.name, 'data') + self._options(kw))

def append(self, binarydata, **kw):
     """Appends binary string data to the end of the sound."""
     self.tk.call((self.name, 'append', binarydata) + self._options(kw))


When loading sound data as for example:
Code:

#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-

import Tkinter
import tkSnack

root = Tkinter.Tk()
tkSnack.initializeSnack(root)

s = tkSnack.Sound()
data = open('ex1.wav', 'rb').read()
s.data(data, fileformat='WAV')
s.write('copy.wav', fileformat='WAV')

It doesn't work because of the TCL function Tcl_GetByteArrayFromObj() (in generic/jkSoundFile.c called by GetHeader() and ReadSound()). This function applies a conversion of the data to a bytearray. This conversion has probably to do with string encodings.
I don't know how to tell TCL not to modify the binary data. One "dirty" solution is to set variable useOldObjAPI to 1 in generic/snack.c or to use older tcl version. The conversion is not performed then and the python script works fine.

I understand now why those features are not implemented icon_cry.gif
Back to top
View users profile Send private message
kare



Joined: 16 Aug 2002
Posts: 371
Location: KTH, Centre for Speech Technology

PostPosted: Wed Oct 13, 2004 9:27 pm    Post subject: Reply with quote

Thanks for a really interesting investigation. I'll look into this problem again and get back to you.

Kåre
Back to top
View users profile Send private message Visit posters website
kare



Joined: 16 Aug 2002
Posts: 371
Location: KTH, Centre for Speech Technology

PostPosted: Wed Oct 20, 2004 3:52 pm    Post subject: Reply with quote

Hello again,

I've implemented a hidden Snack command that sets the flag useOldObjAPI. This call is done in initializeSnack(). With this minimal modification your script runs fine with modern Tcl versions. If it works for you this will be a nice improvement in the next release!

Try it out http://www.speech.kth.se/~kare/snack2.2.8n.tar.gz

I've included your script as a Python demo.

Kåre
Back to top
View users profile Send private message Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    www.speech.kth.se/wavesurfer Forum Index -> WaveSurfer All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.1 © 2001, 2002 phpBB Group