@jambonz/speech-utils 1.0.22 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/synth-audio.js +22 -11
- package/package.json +1 -1
package/lib/synth-audio.js
CHANGED
|
@@ -1879,8 +1879,18 @@ const synthSvara = async(logger, {
|
|
|
1879
1879
|
const synthFishaudio = async(logger, {
|
|
1880
1880
|
credentials, options, stats, voice, key, text, renderForCaching, disableTtsStreaming, disableTtsCache
|
|
1881
1881
|
}) => {
|
|
1882
|
-
const {api_key, model_id
|
|
1883
|
-
|
|
1882
|
+
const {api_key, model_id} = credentials;
|
|
1883
|
+
let credOptions = credentials.options || {};
|
|
1884
|
+
if (typeof credOptions === 'string') {
|
|
1885
|
+
try {
|
|
1886
|
+
credOptions = JSON.parse(credOptions);
|
|
1887
|
+
} catch {
|
|
1888
|
+
credOptions = {};
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
/* Extra Options on the credential apply to every request; the verb's options win */
|
|
1892
|
+
const {reference_id, latency, chunk_length, speed, volume, api_uri} = {...credOptions, ...options};
|
|
1893
|
+
const isSet = (v) => v !== null && v !== undefined && v !== '';
|
|
1884
1894
|
|
|
1885
1895
|
/* free-text reference_id in the vendor options wins over the voice selector */
|
|
1886
1896
|
const refId = reference_id || (voice && voice !== 'default' ? voice : null);
|
|
@@ -1895,10 +1905,10 @@ const synthFishaudio = async(logger, {
|
|
|
1895
1905
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
|
1896
1906
|
if (model_id) params += `,model_id=${model_id}`;
|
|
1897
1907
|
if (latency) params += `,latency=${latency}`;
|
|
1898
|
-
if (chunk_length) params += `,chunk_length=${chunk_length}`;
|
|
1899
|
-
if (speed) params += `,speed=${speed}`;
|
|
1900
|
-
if (volume) params += `,volume=${volume}`;
|
|
1901
|
-
if (
|
|
1908
|
+
if (isSet(chunk_length)) params += `,chunk_length=${chunk_length}`;
|
|
1909
|
+
if (isSet(speed)) params += `,speed=${speed}`;
|
|
1910
|
+
if (isSet(volume)) params += `,volume=${volume}`;
|
|
1911
|
+
if (api_uri) params += `,api_uri=${api_uri}`;
|
|
1902
1912
|
params += '}';
|
|
1903
1913
|
|
|
1904
1914
|
return {
|
|
@@ -1910,7 +1920,8 @@ const synthFishaudio = async(logger, {
|
|
|
1910
1920
|
|
|
1911
1921
|
try {
|
|
1912
1922
|
const sampleRate = 8000;
|
|
1913
|
-
const
|
|
1923
|
+
const host = (api_uri || 'api.fish.audio').replace(/^[a-z]+:\/\//, '').replace(/\/$/, '');
|
|
1924
|
+
const post = bent(`https://${host}`, 'POST', 'buffer', {
|
|
1914
1925
|
'Authorization': `Bearer ${api_key}`,
|
|
1915
1926
|
'Content-Type': 'application/json',
|
|
1916
1927
|
/* the model is selected by header, not in the body */
|
|
@@ -1922,10 +1933,10 @@ const synthFishaudio = async(logger, {
|
|
|
1922
1933
|
sample_rate: sampleRate,
|
|
1923
1934
|
...(refId && {reference_id: refId}),
|
|
1924
1935
|
...(latency && {latency}),
|
|
1925
|
-
...(chunk_length && {chunk_length: parseInt(chunk_length, 10)}),
|
|
1926
|
-
...((speed || volume) && {prosody: {
|
|
1927
|
-
...(speed && {speed: parseFloat(speed)}),
|
|
1928
|
-
...(volume && {volume: parseFloat(volume)})
|
|
1936
|
+
...(isSet(chunk_length) && {chunk_length: parseInt(chunk_length, 10)}),
|
|
1937
|
+
...((isSet(speed) || isSet(volume)) && {prosody: {
|
|
1938
|
+
...(isSet(speed) && {speed: parseFloat(speed)}),
|
|
1939
|
+
...(isSet(volume) && {volume: parseFloat(volume)})
|
|
1929
1940
|
}})
|
|
1930
1941
|
});
|
|
1931
1942
|
return {
|