Spaces:
Sleeping
Sleeping
File size: 13,328 Bytes
61d39e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
/* eslint-disable */
// TODO: Make these more compatible with eslint
// Core test functions for txt2speech functionality
const testTxt2SpeechBasicCore = async function() {
// Test basic text-to-speech with simple text
const result = await puter.ai.txt2speech("Hello, this is a test message.");
// Check that result is an Audio object
assert(result instanceof Audio, "txt2speech should return an Audio object");
assert(result !== null, "txt2speech should not return null");
// Check that Audio object has proper methods
assert(typeof result.play === 'function', "result should have play method");
assert(typeof result.pause === 'function', "result should have pause method");
assert(typeof result.toString === 'function', "result should have toString method");
assert(typeof result.valueOf === 'function', "result should have valueOf method");
// Get the actual values to debug
const toStringValue = result.toString();
const valueOfValue = result.valueOf();
const srcValue = result.src;
// Check that toString() and valueOf() return strings
assert(typeof toStringValue === 'string', `toString() should return a string, got: ${typeof toStringValue} with value: ${toStringValue}`);
assert(typeof valueOfValue === 'string', `valueOf() should return a string, got: ${typeof valueOfValue} with value: ${valueOfValue}`);
// Check that the URL is valid (could be blob: or data: or http:)
assert(toStringValue.length > 0, "toString() should not return empty string");
assert(valueOfValue.length > 0, "valueOf() should not return empty string");
// Check that it's a valid URL format (blob:, data:, http:, or https:)
const isValidUrl = toStringValue.startsWith('blob:') ||
toStringValue.startsWith('data:') ||
toStringValue.startsWith('http:') ||
toStringValue.startsWith('https:');
assert(isValidUrl, `toString() should return a valid URL, got: ${toStringValue}`);
// Check that src is set and is a valid URL
assert(typeof srcValue === 'string', "result should have src property as string");
assert(srcValue.length > 0, "src should not be empty");
// Verify toString() and valueOf() return the same value as src
assert(toStringValue === srcValue, `toString() should return the same as src. toString(): ${toStringValue}, src: ${srcValue}`);
assert(valueOfValue === srcValue, `valueOf() should return the same as src. valueOf(): ${valueOfValue}, src: ${srcValue}`);
};
const testTxt2SpeechWithParametersCore = async function() {
// Test text-to-speech with language and voice parameters
const result = await puter.ai.txt2speech("Hello, this is a test with parameters.", "en-US", "Brian");
// Check that result is an Audio object
assert(result instanceof Audio, "txt2speech should return an Audio object");
assert(result !== null, "txt2speech should not return null");
// Check that Audio object has proper methods
assert(typeof result.play === 'function', "result should have play method");
assert(typeof result.pause === 'function', "result should have pause method");
assert(typeof result.toString === 'function', "result should have toString method");
assert(typeof result.valueOf === 'function', "result should have valueOf method");
// Get the actual values to debug
const toStringValue = result.toString();
const valueOfValue = result.valueOf();
const srcValue = result.src;
// Check that toString() and valueOf() return strings
assert(typeof toStringValue === 'string', `toString() should return a string, got: ${typeof toStringValue} with value: ${toStringValue}`);
assert(typeof valueOfValue === 'string', `valueOf() should return a string, got: ${typeof valueOfValue} with value: ${valueOfValue}`);
// Check that the URL is valid (could be blob: or data: or http:)
assert(toStringValue.length > 0, "toString() should not return empty string");
assert(valueOfValue.length > 0, "valueOf() should not return empty string");
// Check that it's a valid URL format
const isValidUrl = toStringValue.startsWith('blob:') ||
toStringValue.startsWith('data:') ||
toStringValue.startsWith('http:') ||
toStringValue.startsWith('https:');
assert(isValidUrl, `toString() should return a valid URL, got: ${toStringValue}`);
// Check that src is set and is a valid URL
assert(typeof srcValue === 'string', "result should have src property as string");
assert(srcValue.length > 0, "src should not be empty");
// Verify toString() and valueOf() return the same value as src
assert(toStringValue === srcValue, `toString() should return the same as src. toString(): ${toStringValue}, src: ${srcValue}`);
assert(valueOfValue === srcValue, `valueOf() should return the same as src. valueOf(): ${valueOfValue}, src: ${srcValue}`);
// Verify that different parameters produce different audio (comparing with basic call)
const basicResult = await puter.ai.txt2speech("Hello, this is a test with parameters.");
assert(result.src !== basicResult.src, "different parameters should produce different audio URLs");
};
const testTxt2SpeechWithTestModeCore = async function() {
// Test text-to-speech with testMode enabled
const result = await puter.ai.txt2speech("Hello, this is a test message.", "en-US", true);
// Check that result is an Audio object (same structure in test mode)
assert(result instanceof Audio, "txt2speech should return an Audio object in test mode");
assert(result !== null, "txt2speech should not return null in test mode");
// Check that Audio object has proper methods
assert(typeof result.play === 'function', "result should have play method in test mode");
assert(typeof result.pause === 'function', "result should have pause method in test mode");
assert(typeof result.toString === 'function', "result should have toString method in test mode");
assert(typeof result.valueOf === 'function', "result should have valueOf method in test mode");
// Get the actual values to debug
const toStringValue = result.toString();
const valueOfValue = result.valueOf();
const srcValue = result.src;
// Check that toString() and valueOf() return strings
assert(typeof toStringValue === 'string', `toString() should return a string in test mode, got: ${typeof toStringValue} with value: ${toStringValue}`);
assert(typeof valueOfValue === 'string', `valueOf() should return a string in test mode, got: ${typeof valueOfValue} with value: ${valueOfValue}`);
// Check that the URL is valid (could be blob: or data: or http:)
assert(toStringValue.length > 0, "toString() should not return empty string in test mode");
assert(valueOfValue.length > 0, "valueOf() should not return empty string in test mode");
// Check that it's a valid URL format
const isValidUrl = toStringValue.startsWith('blob:') ||
toStringValue.startsWith('data:') ||
toStringValue.startsWith('http:') ||
toStringValue.startsWith('https:');
assert(isValidUrl, `toString() should return a valid URL in test mode, got: ${toStringValue}`);
// Check that src is set and is a valid URL
assert(typeof srcValue === 'string', "result should have src property as string in test mode");
assert(srcValue.length > 0, "src should not be empty in test mode");
// Verify toString() and valueOf() return the same value as src
assert(toStringValue === srcValue, `toString() should return the same as src in test mode. toString(): ${toStringValue}, src: ${srcValue}`);
assert(valueOfValue === srcValue, `valueOf() should return the same as src in test mode. valueOf(): ${valueOfValue}, src: ${srcValue}`);
};
const testTxt2SpeechWithOpenAIProviderCore = async function() {
// Test OpenAI-based text-to-speech using test mode to avoid live requests
const result = await puter.ai.txt2speech("Hello, this is an OpenAI provider test.", { provider: "openai", voice: "alloy" }, true);
assert(result instanceof Audio, "txt2speech should return an Audio object for OpenAI provider");
assert(result !== null, "txt2speech should not return null for OpenAI provider");
const toStringValue = result.toString();
const valueOfValue = result.valueOf();
const srcValue = result.src;
assert(typeof toStringValue === 'string', "toString() should return a string for OpenAI provider");
assert(typeof valueOfValue === 'string', "valueOf() should return a string for OpenAI provider");
assert(typeof srcValue === 'string', "src should be a string for OpenAI provider");
assert(toStringValue.length > 0, "toString() should not be empty for OpenAI provider");
assert(valueOfValue.length > 0, "valueOf() should not be empty for OpenAI provider");
assert(srcValue.length > 0, "src should not be empty for OpenAI provider");
assert(toStringValue === srcValue, "toString() should match src for OpenAI provider");
assert(valueOfValue === srcValue, "valueOf() should match src for OpenAI provider");
};
const testTxt2SpeechWithElevenLabsProviderCore = async function() {
// Test ElevenLabs provider in test mode to avoid external calls
const result = await puter.ai.txt2speech(
"Hello, this is an ElevenLabs provider test.",
{ provider: "elevenlabs", voice: "21m00Tcm4TlvDq8ikWAM" },
true,
);
assert(result instanceof Audio, "txt2speech should return an Audio object for ElevenLabs provider");
assert(result !== null, "txt2speech should not return null for ElevenLabs provider");
const toStringValue = result.toString();
const valueOfValue = result.valueOf();
const srcValue = result.src;
assert(typeof toStringValue === 'string', "toString() should return a string for ElevenLabs provider");
assert(typeof valueOfValue === 'string', "valueOf() should return a string for ElevenLabs provider");
assert(typeof srcValue === 'string', "src should be a string for ElevenLabs provider");
assert(toStringValue.length > 0, "toString() should not be empty for ElevenLabs provider");
assert(valueOfValue.length > 0, "valueOf() should not be empty for ElevenLabs provider");
assert(srcValue.length > 0, "src should not be empty for ElevenLabs provider");
assert(toStringValue === srcValue, "toString() should match src for ElevenLabs provider");
assert(valueOfValue === srcValue, "valueOf() should match src for ElevenLabs provider");
};
// Export test functions
window.txt2speechTests = [
{
name: "testTxt2SpeechBasic",
description: "Test basic text-to-speech functionality and verify Audio object structure",
test: async function() {
try {
await testTxt2SpeechBasicCore();
pass("testTxt2SpeechBasic passed");
} catch (error) {
fail("testTxt2SpeechBasic failed:", error);
}
}
},
{
name: "testTxt2SpeechWithParameters",
description: "Test text-to-speech with language and voice parameters (en-US, Brian)",
test: async function() {
try {
await testTxt2SpeechWithParametersCore();
pass("testTxt2SpeechWithParameters passed");
} catch (error) {
fail("testTxt2SpeechWithParameters failed:", error);
}
}
},
{
name: "testTxt2SpeechWithTestMode",
description: "Test text-to-speech with testMode enabled to verify test functionality",
test: async function() {
try {
await testTxt2SpeechWithTestModeCore();
pass("testTxt2SpeechWithTestMode passed");
} catch (error) {
fail("testTxt2SpeechWithTestMode failed:", error);
}
}
},
{
name: "testTxt2SpeechWithOpenAIProvider",
description: "Test text-to-speech using the OpenAI provider in test mode",
test: async function() {
try {
await testTxt2SpeechWithOpenAIProviderCore();
pass("testTxt2SpeechWithOpenAIProvider passed");
} catch (error) {
fail("testTxt2SpeechWithOpenAIProvider failed:", error);
}
}
},
{
name: "testTxt2SpeechWithElevenLabsProvider",
description: "Test text-to-speech using the ElevenLabs provider in test mode",
test: async function() {
try {
await testTxt2SpeechWithElevenLabsProviderCore();
pass("testTxt2SpeechWithElevenLabsProvider passed");
} catch (error) {
fail("testTxt2SpeechWithElevenLabsProvider failed:", error);
}
}
}
];
|