Robert Klemme
6/27/2006 2:04:00 PM
yuri.leikind@gmail.com wrote:
>> I'm afraid this is a bit too few information.
>
> Mayby you are right
>
>> Are you sure the server
>> doesn't actually write 0d0d0a and your Perl client just discards the
>> first 0d - either during reading or printing?
>
> Absolutely. The thing is that the output is actually a wav file. The
> perl client produces a valid wav file while the ruby client doesn't.
>
>> Personally I'd try to use
>> a smaller buffer size - something like 4096.
>
> Done it. No effect.
As I said, I don't expect that to cure the issue. :-)
>> Other than that, I'd suggest you post a bit more code. You could also
>> write a simplistic server in Ruby using TCPServer (test with writing
>> "0d0d0a" and "0d0a") and test both of your scripts against it. HTH
>
>
> Ok. The server is actually a text-to-speech system and it is accessible
> in the Internet.
>
> I have simplified both the perl and the ruby client as much as possible
> and you can find them below. The algorythm is simple - you open a
> socket, write a command and read an id. The open a socket again, write
> the id and some natural text message (in case of this publicly
> available server the language is german).
>
>
> === PERL ===
> #!/usr/bin/env perl
>
> use IO::Socket;
>
> $host = "cling.dfki.uni-sb.de";
> #$host = "localhost";
>
> $maryInfoSocket = IO::Socket::INET->new(Proto => "tcp",
> PeerAddr => $host,
> PeerPort => 59125);
> $maryInfoSocket->autoflush(1);
>
> print $maryInfoSocket "MARY IN=TEXT_EN OUT=AUDIO AUDIO=WAVE";
> #print $maryInfoSocket "MARY IN=TEXT_EN OUT=RAWMARYXML"; # this will
> result in text output
> print $maryInfoSocket "\015\012";
>
> $id = <$maryInfoSocket>;
> chomp $id; chomp $id;
>
> $maryDataSocket = IO::Socket::INET->new(Proto => "tcp",
> PeerAddr => $host,
> PeerPort => 59125);
> print $maryDataSocket $id, "\015\012";
>
> #print $maryDataSocket "Hello world";
> print $maryDataSocket "Hallo Welt";
>
> print $maryDataSocket "\015\012";
>
> shutdown($maryDataSocket, 1);
>
> open(OUT, ">out.pl.wav");
> while($nr = read($maryDataSocket, $buf, 4096)) {
> print OUT $buf;
> }
>
> ===========
>
> === RUBY ===
>
> #!/usr/bin/env ruby
>
> require 'socket'
>
> host = "cling.dfki.uni-sb.de";
> #host = "localhost";
>
> maryInfoSocket = TCPSocket.new(host, 59125)
> maryInfoSocket.binmode()
>
> maryInfoSocket.write("MARY IN=TEXT_EN OUT=AUDIO AUDIO=WAVE")
> #maryInfoSocket.write("MARY IN=TEXT_EN OUT=RAWMARYXML") # this will
> result in text output
>
> maryInfoSocket.write "\015\012"
> maryInfoSocket.flush
>
> id = maryInfoSocket.gets
>
> id.chomp!
>
> maryDataSocket = TCPSocket.new(host, 59125)
> maryDataSocket.binmode()
I don't think there is a binmode for sockets - doesn't really seem to
make sense. IMHO sockets are *always* binary.
> maryDataSocket.write id + "\015\012"
> maryDataSocket.flush
>
> #maryDataSocket.write "Hello world" + "\015\012"
> maryDataSocket.write "Hallo Welt" + "\015\012"
>
> maryDataSocket.flush
> maryDataSocket.close_write
>
>
> File.open("out.rb.wav", "w"){|f|
Use file mode "wb" regardless of operating system.
> while out = maryDataSocket.read(4096)
> f.write(out)
> end
> }
>
> ===========
>
> What am I missing here? Why are the results different?
Another remark: I'd use the block form of TCPSocket.open, like in
TCPSocket.open(host, 59125) do |sock|
...
end
Kind regards
robert