[Voiceglue] Hashing filenames
Andrew Cumming
andrewc at kestral.com.au
Tue Jan 13 18:05:24 EST 2009
I found that some long text (and some not so long) would create very
long filenames. I think this also caused some problems when the
filenames got exceedingly long.
Following are some changes I made to /usr/bin/voiceglue
After "Use Vxglue;" add "use Digest::SHA1 qw(sha1 sha1_hex sha1_base64);
Modify the following function in /usr/bin/voiceglue
## ($ok, $msg, $base_path) = sc_request_to_base_path ($type, $item);
## -- Given a sounc cache request $type and $item, returns
## the base file path (no leading path/prefix).
## On error $ok is false, and $msg is an error message
sub sc_request_to_base_path
{
my ($type) = shift (@_);
my ($item) = shift (@_);
my ($fixed_name, @path_chars, $base_path, @components);
if ($type eq "tts")
{
@path_chars = split (//, $item);
$fixed_name = join ("", map (sc_translate_path_char ($_),
@path_chars));
$base_path = join ("/", $type, sha1_hex($fixed_name) . ".wav");
## edit this line
}
elsif ($type eq "url")
{
@components = split (/\//, $item);
if (scalar (@components) < 4)
{
return (0, "Insufficient URL components in path for
\"$item\"");
};
if (! length ($components[2]))
{
$components[2] = "+";
};
splice (@components, 0, 2);
$base_path = join ("/", $type, @components);
};
return (1, "", $base_path);
};
The "edit this line" has the sha1 function added.
This probably isn't the perfect solution, but it seems to do the job. As
my perl is pretty poor, if anyone can see any problems feel free to
alert me.
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.voiceglue.org/pipermail/voiceglue/attachments/20090114/b151d331/attachment.html
More information about the Voiceglue
mailing list