1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- import mlrun
15+ import os
1616import tempfile
17+
18+ import mlrun
1719import pytest
1820
1921
@@ -31,6 +33,7 @@ def test_generate_multi_speakers_audio(file_format, bits_per_sample):
3133 "v2/en_speaker_0" ,
3234 "v2/en_speaker_1" ,
3335 ],
36+ "engine" : "bark" ,
3437 "use_small_models" : True ,
3538 "use_gpu" : False ,
3639 "offload_cpu" : True ,
@@ -45,6 +48,42 @@ def test_generate_multi_speakers_audio(file_format, bits_per_sample):
4548 ],
4649 artifact_path = test_directory ,
4750 )
48- assert function_run .error == "Run state (completed) is not in error state "
51+ assert function_run .error == ""
4952 for key in ["audio_files" , "audio_files_dataframe" , "text_to_speech_errors" ]:
5053 assert key in function_run .outputs and function_run .outputs [key ] is not None
54+
55+
56+ @pytest .mark .skipif (
57+ condition = os .getenv ("OPENAI_API_BASE" ) is None
58+ and os .getenv ("OPENAI_API_KEY" ) is None ,
59+ reason = "OpenAI API key and base URL are required to run this test" ,
60+ )
61+ @pytest .mark .parametrize ("file_format,bits_per_sample" , [("wav" , 8 ), ("mp3" , None )])
62+ def test_generate_multi_speakers_audio_openai (file_format , bits_per_sample ):
63+ text_to_audio_generator_function = mlrun .import_function ("function.yaml" )
64+ with tempfile .TemporaryDirectory () as test_directory :
65+ function_run = text_to_audio_generator_function .run (
66+ handler = "generate_multi_speakers_audio" ,
67+ inputs = {"data_path" : "data/test_data.txt" },
68+ params = {
69+ "output_directory" : test_directory ,
70+ "speakers" : {"Agent" : 0 , "Client" : 1 },
71+ "available_voices" : [
72+ "alloy" ,
73+ "echo" ,
74+ ],
75+ "engine" : "openai" ,
76+ "file_format" : file_format ,
77+ "bits_per_sample" : bits_per_sample ,
78+ },
79+ local = True ,
80+ returns = [
81+ "audio_files: path" ,
82+ "audio_files_dataframe: dataset" ,
83+ "text_to_speech_errors: file" ,
84+ ],
85+ artifact_path = test_directory ,
86+ )
87+ assert function_run .error == ""
88+ for key in ["audio_files" , "audio_files_dataframe" , "text_to_speech_errors" ]:
89+ assert key in function_run .outputs and function_run .outputs [key ] is not None
0 commit comments