Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

force_align.py (TypeError: a bytes-like object is required, not 'str') #58

Open
ChristineBasta opened this issue Mar 17, 2021 · 3 comments

Comments

@ChristineBasta
Copy link

Hello,
we are trying to run force_align after using the fast_align, the fast_align is working fine and we get the model.
After running force_align, we get Traceback (most recent call last):
File "/home/christine/fast_align/build/force_align.py", line 93, in
main()
File "/home/christine/fast_align/build/force_align.py", line 87, in main
sys.stdout.write('{}\n'.format(aligner.align(line.strip())))
File "/home/christine/fast_align/build/force_align.py", line 30, in align
self.fwd_align.stdin.write('{}\n'.format(line))
TypeError: a bytes-like object is required, not 'str'

we are running on python 3.6.9.

we do not know where the problem can be from, we are using the right format of sentence:
The mechanic gave the clerk a present because it was his birthday. ||| La mecánica dio al Cirque durargo, porque era su cumpleaños.

please advise!!

@lluisg
Copy link

lluisg commented Mar 17, 2021

We tried changing to bites with

        self.fwd_align.stdin.write('{}\n'.format(line).encode('utf-8'))

but then the problem persists and gets stuck on the next line

        fwd_line = self.fwd_align.stdout.readline().split('|||')[2].strip()

@ttwelve12
Copy link

ttwelve12 commented Jun 1, 2021

Hi, if you use python3, you should set bufsize = 1 and universal_newlines= True in subprocess.Popen .
@lluisg @ChristineBasta
And you can also set the "encoding" in module subprocess if you meet encode problem

cbaziotis added a commit to cbaziotis/fast_align that referenced this issue Jun 8, 2021
Compatibility with python 3 (fixes `TypeError: a bytes-like object is required, not 'str'`) clab#58
@lizongyao123
Copy link

Python2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants