Skip to content

Commit

Permalink
update audio output (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhangpurdue authored Jul 5, 2024
1 parent 374f2eb commit 6e4788d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion modelscope_agent/tools/dashscope_tools/sambert_tts_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ def call(self, params: str, **kwargs) -> str:
raise ValueError(
f'call sambert tts failed, request id: {response.get_response()}'
)
return str(AudioWrapper(wav_file))
return str(AudioWrapper(wav_file, **kwargs))
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ def call(self, params: str, **kwargs) -> str:
print('speech_generation error: ', result)
return None
audio = result['Data']['output_wav']
if 'use_tool_api' in kwargs:
return audio
else:
return str(AudioWrapper(audio))
return str(AudioWrapper(audio, **kwargs))

def _verify_args(self, params: str):
# override the args
Expand Down
19 changes: 11 additions & 8 deletions modelscope_agent/tools/utils/output_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,22 @@ class AudioWrapper(OutputWrapper):
Audio wrapper, raw_data is a binary file
"""

def __init__(self, audio) -> None:
def __init__(self, audio, **kwargs) -> None:

super().__init__()
if isinstance(audio, str):
if os.path.isfile(audio):
if 'use_tool_api' in kwargs and 'https://' in audio:
self._path = audio
else:
self._path = self.get_remote_file(audio, 'wav')
try:
with open(self._path, 'rb') as f:
self._raw_data = f.read()
except FileNotFoundError:
raise FileNotFoundError(f'Invalid path: {audio}')
if os.path.isfile(audio):
self._path = audio
else:
self._path = self.get_remote_file(audio, 'wav')
try:
with open(self._path, 'rb') as f:
self._raw_data = f.read()
except FileNotFoundError:
raise FileNotFoundError(f'Invalid path: {audio}')
else:
self._raw_data = audio
directory = tempfile.mkdtemp(dir=self.root_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/tools/test_modelscope_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_modelscope_speech_generation_with_tool_api():
kwargs = {'use_tool_api': True}
txt2speech = TexttoSpeechTool()
res = txt2speech.call(params, **kwargs)
assert res.startswith('https://')
assert res.startswith('<audio src="https://')


@pytest.mark.skipif(IS_FORKED_PR, reason='only run modelscope-agent main repo')
Expand Down

0 comments on commit 6e4788d

Please sign in to comment.