Skip to content

Commit

Permalink
done: json file works
Browse files Browse the repository at this point in the history
  • Loading branch information
feyhoa committed Oct 6, 2023
1 parent 41a02f6 commit b14bbd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 4 additions & 5 deletions voice_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@


def audio_to_text(filename):
response = get_att_whisper(filename, 'txt')
response = get_att_whisper(filename)

if response.status_code == 200:
transcription = filename.split('.')[0] + '.json'
result_json = json.dumps(transcription)
recognized_data = json.loads(result_json)

input_sentence = RecognizedSentence(recognized_data)
input_sentence = RecognizedSentence(response.json())
return input_sentence

return None


def download_voice(update: Update):
downloaded_file = update.message.voice.get_file()
Expand Down
11 changes: 7 additions & 4 deletions whisper_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class WhisperSettings:
asr_model = ASR_MODEL


def get_att_whisper(filename, output: str = 'json'):
def get_att_whisper(filename):
"""
filename: str
audio file name
Expand All @@ -19,8 +19,11 @@ def get_att_whisper(filename, output: str = 'json'):
"txt", "vtt", "srt", "tsv", "json"
"""

file = {'audio_file': (filename, open(filename, 'rb'))}
data = {'task': 'transcribe', 'output': output, 'word_timestamps': 'true'}
response = requests.post(WhisperSettings.link + '/asr', data=data, files=file)
with open(filename, 'rb') as f_byte:
file = {'audio_file': (filename, f_byte)}

response = requests.post(WhisperSettings.link +
'/asr?task=transcribe&encode=false&output=json&word_timestamps=true',
files=file)

return response

0 comments on commit b14bbd9

Please sign in to comment.