diff --git a/binding/python/test_orca.py b/binding/python/test_orca.py index ebed17ff..13cf2278 100644 --- a/binding/python/test_orca.py +++ b/binding/python/test_orca.py @@ -62,8 +62,8 @@ def _test_word_equal(self, word: Orca.WordAlignment, word_truth: Orca.WordAlignm self._test_equal_timestamp(word.start_sec, word_truth.start_sec) self._test_equal_timestamp(word.end_sec, word_truth.end_sec) - for i, phoneme in enumerate(word.phonemes): - phoneme_truth = word_truth.phonemes[i] + self.assertEqual(len(word.phonemes), len(word_truth.phonemes)) + for phoneme, phoneme_truth in zip(word.phonemes, word_truth.phonemes): self._test_phoneme_equal(phoneme, phoneme_truth) @staticmethod @@ -108,30 +108,31 @@ def test_synthesize_alignment_exact(self) -> None: pcm, alignments = orca.synthesize(test_data.text_alignment, random_state=test_data.random_state) self.assertGreater(len(pcm), 0) - for i, word in enumerate(alignments): - word_truth = test_data.alignments[i] + self.assertTrue(len(alignments) == len(test_data.alignments)) + for word, word_truth in zip(alignments, test_data.alignments): self._test_word_equal(word, word_truth) def test_synthesize_alignment(self) -> None: for i, orca in enumerate(self.orcas): - if self.EXACT_ALIGNMENT_TEST_MODEL_IDENTIFIER not in self.model_paths[i]: + if self.EXACT_ALIGNMENT_TEST_MODEL_IDENTIFIER in self.model_paths[i]: + continue - pcm, alignments = orca.synthesize(test_data.text_alignment, random_state=test_data.random_state) - self.assertGreater(len(pcm), 0) + pcm, alignments = orca.synthesize(test_data.text_alignment, random_state=test_data.random_state) + self.assertGreater(len(pcm), 0) - previous_word_end_sec = 0 - previous_phoneme_end_sec = 0 - for word in alignments: - self.assertTrue(word.start_sec == previous_word_end_sec) - self.assertTrue(word.end_sec > word.start_sec) - previous_word_end_sec = word.end_sec + previous_word_end_sec = 0 + previous_phoneme_end_sec = 0 + for word in alignments: + self.assertTrue(word.start_sec == previous_word_end_sec) + self.assertTrue(word.end_sec > word.start_sec) + previous_word_end_sec = word.end_sec - for phoneme in word.phonemes: - self.assertTrue(phoneme.start_sec == previous_phoneme_end_sec) - self.assertTrue(phoneme.start_sec >= word.start_sec) - self.assertTrue(phoneme.end_sec <= word.end_sec) - self.assertTrue(phoneme.end_sec > phoneme.start_sec) - previous_phoneme_end_sec = phoneme.end_sec + for phoneme in word.phonemes: + self.assertTrue(phoneme.start_sec == previous_phoneme_end_sec) + self.assertTrue(phoneme.start_sec >= word.start_sec) + self.assertTrue(phoneme.end_sec <= word.end_sec) + self.assertTrue(phoneme.end_sec > phoneme.start_sec) + previous_phoneme_end_sec = phoneme.end_sec def test_streaming_synthesis(self) -> None: for i, orca in enumerate(self.orcas): @@ -162,12 +163,8 @@ def test_synthesize_speech_rate(self) -> None: self.assertLess(len(pcm_fast), len(pcm_slow)) - try: + with self.assertRaises(OrcaError): _ = orca.synthesize(test_data.text, speech_rate=9999) - except OrcaError: - pass - else: - self.fail("Expected OrcaError") def test_synthesize_to_file(self) -> None: for orca in self.orcas: diff --git a/binding/python/test_util.py b/binding/python/test_util.py index f39c6e9e..20c0e686 100644 --- a/binding/python/test_util.py +++ b/binding/python/test_util.py @@ -12,7 +12,7 @@ import json import os from dataclasses import dataclass -from typing import List, Sequence, Set +from typing import List, Sequence import soundfile @@ -33,7 +33,7 @@ class TestData: def read_wav_file(path: str) -> Sequence[int]: pcm, _ = soundfile.read(path) - pcm = list((pcm * 32768)) + pcm = list(pcm * 32768) return pcm @@ -47,10 +47,8 @@ def get_test_data() -> TestData: with open(data_file_path, encoding="utf8") as data_file: test_data = json.loads(data_file.read()) - alignment_data = test_data["alignments"] - alignments = [] - for word_data in alignment_data: + for word_data in test_data["alignments"]: phonemes = [] for phoneme_data in word_data["phonemes"]: phoneme = Orca.PhonemeAlignment( diff --git a/demo/llm/requirements.txt b/demo/llm/requirements.txt new file mode 100644 index 00000000..164bbbb6 --- /dev/null +++ b/demo/llm/requirements.txt @@ -0,0 +1,3 @@ +sounddevice +tiktoken +openai diff --git a/demo/llm/src/llm.py b/demo/llm/src/llm.py index 5aeb3ff4..73a37914 100644 --- a/demo/llm/src/llm.py +++ b/demo/llm/src/llm.py @@ -79,11 +79,7 @@ def _tokenize(self, text: str) -> Sequence[str]: return tokens def _chat(self, user_input: str) -> Generator[str, None, None]: - try: - text_index = int(user_input) - sentence = self._sentences[text_index] - except ValueError: - sentence = self._sentences[random.randint(0, len(self._sentences) - 1)] + sentence = self._sentences[random.randint(0, len(self._sentences) - 1)] for i in self._tokenize(text=sentence): time.sleep(self._tokens_delay) diff --git a/demo/python/orca_demo.py b/demo/python/orca_demo.py index 25754b8c..400998e4 100644 --- a/demo/python/orca_demo.py +++ b/demo/python/orca_demo.py @@ -55,11 +55,11 @@ def main(): pcm, alignment = orca.synthesize(args.text) processing_time = time.time() - start length_sec = len(pcm) / orca.sample_rate - with wave.open(args.output_path, 'wb') as output_file: + with wave.open(args.output_path, "wb") as output_file: output_file.setnchannels(1) output_file.setsampwidth(2) output_file.setframerate(orca.sample_rate) - output_file.writeframes(struct.pack('%dh' % len(pcm), *pcm)) + output_file.writeframes(struct.pack(f"{len(pcm)}h", *pcm)) print( f"Orca took {processing_time:.2f} seconds to synthesize {length_sec:.2f} seconds of speech which is " f"~{length_sec / processing_time:.0f} times faster than real-time.") diff --git a/demo/python/requirements.txt b/demo/python/requirements.txt index 8a8d04b9..d52a04df 100644 --- a/demo/python/requirements.txt +++ b/demo/python/requirements.txt @@ -1,5 +1,2 @@ ../../binding/python/dist/pvorca-0.1.4-py3-none-any.whl pvorca==0.1.4 -sounddevice -tiktoken -openai diff --git a/lib/ios/PvOrca.xcframework/ios-arm64_x86_64-simulator/PvOrca.framework/Headers/picovoice.h b/lib/ios/PvOrca.xcframework/ios-arm64_x86_64-simulator/PvOrca.framework/Headers/picovoice.h index 31a8127f..80faad58 100644 --- a/lib/ios/PvOrca.xcframework/ios-arm64_x86_64-simulator/PvOrca.framework/Headers/picovoice.h +++ b/lib/ios/PvOrca.xcframework/ios-arm64_x86_64-simulator/PvOrca.framework/Headers/picovoice.h @@ -1,5 +1,5 @@ /* - Copyright 2018-2023 Picovoice Inc. + Copyright 2024 Picovoice Inc. You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" file accompanying this source.